Today I saw a tip for HTML text escaping on CSDN, which is very simple.
1. Use the dom function. First pass it to a dom object as innerTEXT, then take the innerHTML attribute, and then you can get the escaped text.
For example:
div1.innerText = <h1>title title....</h1>;
var str = div1.innerHTML; // <h1>title title...
2. Assuming that there is a text context, you can perform $(x).text(context).html() on a jQuery object $(x), and an escaped text will be returned.
var str = $(x).text(context).html()