title title...."; var str = div1.innerHTML; // &"/> title title...."; var str = div1.innerHTML; // &">

Home  >  Article  >  Web Front-end  >  HTML text escaping tips_HTML/Xhtml_Web page production

HTML text escaping tips_HTML/Xhtml_Web page production

WBOY
WBOYOriginal
2016-05-16 16:42:521753browse

Today I saw a little trick for escaping HTML text on CSDN, which is very simple.

1. Use the dom function. Pass it to a DOM object as innerTEXT first, and then get the innerHTML attribute to get the escaped text.

For example:

div1.innerText = "

title title....

";

var str = div1.innerHTML; // "< ;h1>title title..."

2. Assuming there is a text context, you can perform $(x).text(context).html() on a jQuery object $(x), and it will return a The escaped text.

var str = $(x).text(context).html()
Statement:
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