Javascript \ "\ 'im confused

Hey, I'm busy with a little JavaScript element, but the following rule confused me:

<a href="#" onclick="removeMap('+ \"test\" +')" style="float:right; margin-right: 30px;"><img src="images/icons/collapse.gif"></a><br/>'

The onclick remove map action is not removed. I do not know what I need to put between () so that I can put the text there. Anyone have a solution?

thank

+3
source share
5 answers

Try simply:

onclick="removeMap('test')"

if the test is variable:

onclick="removeMap(test)"

\" , onclick. . html, onclick, html double quotes , inline javascript .


, JQuery JavaScript. javascript, .

+8

javascript HTML-, ... !

+2

:

<a href="#" onclick="removeMap('test')" style="float:right; margin-right: 30px;"><img src="images/icons/collapse.gif"></a><br/>'
+1

, ( , , )

0

Escaped quotes do not really matter in HTML. Instead, the browser will see your line as:

<a href="#"
  onclick="removeMap('+ \"
  test\
  " +')"
  style="float:right; margin-right: 30px;"
>

If onclickJavascript is broken and there are two attributes ( test\and " +')") in the tag that it does not recognize and does not know what to do with.

0
source

Source: https://habr.com/ru/post/1764300/


All Articles