1、用dom的功能。先作为innertext传给一个dom对象,再取innerhtml属性,就可以取到转义后的文本了。
例如:
div1.innertext =
title title....;
var str = div1.innerhtml; // <h1>title title...
2、假设有文本 context,可以对一个jquery对象 $(x)进行 $(x).text(context).html(),就会返回一个转义后的文本。
var str = $(x).text(context).html()
