Single and double quotes in JS, HTML, and their escape use
These are used in many cases when the relevant characters are judged or evaluated in JS.
------
A button in a webpage that writes the handling code of the onclick event is accidentally written as follows:
<input value= "Test" type= "button" onclick= "alert (" OK ""); "/>
IE prompt error, then casually changed to:
<input value= "Test" type= "button" onclick= "alert (\" Ok\ ");"/>
The result is still wrong.
At this time, I can not understand, although I know the most direct solution is written like this:
<input value= "" type= "button" onclick= "alert (' OK ');"/>
But why is the escape character in JavaScript \ No effect?
Later, a normal code was found:
<input value= "Test" type= "button" onclick= "alert ("OK");"/>
At this point, it is understood that the original is still attributed to the scope of the HTML, so the escape character should use HTML, rather than JavaScript. The practice of two double quotes is VBScript, \ "This approach is JavaScript, and HTML, it is used ", and also can use:", & #x27.
The following is a list of the various expression methods:
Single and double quotes in JS, HTML, and their escape use