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()