HTML text escaping tips_HTML/Xhtml_Web page production

WBOY
Release: 2016-05-16 16:42:52
Original
1752 people have browsed it

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()
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!