Single and double quotes don't really make a difference, see you're used to it
Copy Code code as follows:
<input type= "button" onclick= "Alert (" 1 ")" >-------------------Incorrect
<input type= "button" onclick= "alert (' 1 ')" >-------------------correct
Double quotes with double quotes to do this:
var str = "abc\" def\ "Ghi"
Use a backslash to prevent the parsing of double quotes.
Here is my excerpt, I hope to be useful to you:
In a Web page The button writes the onclick event's handling code, which is accidentally written as follows:
Copy Code code as follows:
<input value= "Test" type= "button" onclick= "Alert" ("OK"); "/>
When IE prompts an error, then casually change to:
Copy Code code as follows:
<input value= "Test" type= button "onclick=" alert (\ "Ok\"); "/>
The result is still an error.
At this point, I can not figure out, although I know the most direct solution is written in this way:
Copy Code code as follows:
<input value= "type=" button "onclick=" alert (' OK '); "/>
But why does the escape character in JavaScript have no effect?
Then I found a normal code:
Copy Code code as follows:
<input value= "Test" type= "button" onclick= "alert (" OK ");"/>
It was then understood that, at this time, it was still within the jurisdiction of the HTML, so the escape character should be used in HTML instead of JavaScript. Two double quotes are VBScript, \ "This practice is JavaScript, and HTML is used, and in addition, you can use:".
Here are a list of the various expression methods:
Copy Code code as follows:
<body>
<input value= "Outside double quotation mark inside double quotation mark-Error" type= "button" onclick= "alert (" OK ");"/><br/>
<input value= "single quotation mark inside single quotation mark-error ' type= ' button ' onclick= ' Alert (' OK '); '/><br/>
<input value= "Two double quotes-error" type= "button" onclick= "alert (" OK ");"/><br/>
<input value= "Two single quotes-error" type= "button" onclick= "alert (' OK ');"/><br/>
<input value= "\+ double quotes-Error" type= "button" onclick= "alert (\" Ok\ ");"/><br/>
<input value= "\+ single quotes-Error" type= "button" onclick= "alert (\ ' Ok\ ');"/><br/>
<input value= "outside double quotes inside single quotes-ok" type= "button" onclick= "alert (' OK ');"/><br/>
<input value= "Outside single quotation marks inside double quotes-ok" type= "button" onclick= "alert (" OK "); '/><br/>
<input value= "Outside do not use quotation marks-ok" type= "button" Onclick=alert (' OK '); Alert ("OK"); /><br/>
<input value= "HTML escape Character" (& # 3 4;)-ok "type=" button "onclick=" alert ("OK"); "/><br/>
<input value= "HTML escape Character" (& # 3 9;)-ok "type=" button "onclick=" alert (' OK '); "/><br/>
<input value= "HTML escape Character" (& x 2 2;)-ok "type=" button "onclick=" alert (' OK '); "/><br/>
<input value= "HTML escape Character" (& x 2 7;)-ok "type=" button "onclick=" alert (' OK '); "/><br/>
<input value= "HTML escape character" (& q u o t;)-ok "type=" button "onclick=" alert ("OK"); "/><br/>
<input value= "HTML escape Character" (& A P o s;)-ie error "type=" button "onclick=" alert (' OK '); "/><br/>
<input value= "Other \\-Error" type= button "onclick=" alert (\ "ok\\"); "/><br/>
<input value= "Other \& # 3 4;-Error" type= "button" onclick= "alert (\" Ok\ ");"/><br/>
</body>