Home > php教程 > PHP开发 > body text

A brief discussion on the processing of special characters contained in jquery's html method

高洛峰
Release: 2016-12-03 14:27:39
Original
1713 people have browsed it

When using jquery’s html() method, sometimes the html code added inside contains some special characters and needs to be escaped.

The following example:

inst_html = "<a style=color:white&#39; onmouseover = &#39;";
inst_html += "javascript:showme(&#39;"+inst.instId+"_"+valId+"&#39;);";
inst_html += "&#39; ";
$("#inst_div_"+valId).html(inst_html);
Copy after login
Copy after login

If you write it directly like this, there will be no problem under chrome and FF browsers, but an error will be reported under IE8.

The solution is to change 'escape' in javascript to ', so that no error will be reported.

The above example is changed to:

inst_html = "<a style=color:white&#39; onmouseover = &#39;";
inst_html += "javascript:showme(&#39;"+inst.instId+"_"+valId+"&#39;);";
inst_html += "&#39; ";
$("#inst_div_"+valId).html(inst_html);
Copy after login
Copy after login

Some characters are escaped as follows:

•& symbol: "&", "&"
•Double quotes: """, """
•Less-than symbol: "<", "

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template