Single-quote, double-quote HTML escape character----December 2, 2014

Source: Internet
Author: User

'----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 (&quot;OK&quot;);"/>

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 &quot, 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 &quot; (& q u o t;) '-ok" type= "button" onclick= "alert (&quot;OK&quot;);"/>
<br/>
<input value= "HTML escape character &apos; (& A P o s;) '-ok" type= "button" onclick= "alert (&apos;OK&apos;);"/>
<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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.