'----Single quotation marks "-----double quotes
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, and 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:", ".
The following is a list of the various expression methods:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title> This is the label that is displayed in the browser </title>
< Body >
<p> is the same, when it takes two times to use quotation marks, it is recommended to use double quotes outside, using single quotes internally. </p>
<input value= "outer double quotation mark-Error" type= "button" onclick= "alert (" OK ");"/>
<br/>
<input value= "Outer 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 quote-Error" type= "button" onclick= "alert (\ ' Ok\ ');"/>
<br/>
<input value= "outer double quotation mark inside single quotation mark-ok" type= "button" onclick= "alert (' OK ');"/>
<br/>
<input value= "Outer single quotation mark inside double quotes-ok" type= "button" onclick= ' Alert ("OK"); '/>
<br/>
<input value= "External does not use quotation marks-ok" type= "button" Onclick=alert (' OK '); Alert ("OK"); />
<br/>
<input value= "HTML escape Character" (& # 3 4;) '-Error "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;) '-ok" 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 >
< /html >
Single-quote, double-quote HTML escape character----December 2, 2014