话不多说,请看代码:
自带的html()和text()函数可以转义Html字符
* 虚拟一个Div通过赋值和取值来得到想要的Html编码或者解码
*/
获取Html转义字符
function htmlEncode( html ) {
return document.createElement( 'a' ).appendChild(
document.createTextNode( html ) ).parentNode.innerHTML;
};
//获取Html
function htmlDecode( html ) {
var a = document.createElement( 'a' ); a.innerHTML = html;
return a.textContent;
};
/g,">");
s = s.replace(/ /g," ");
s = s.replace(/\'/g,"'");
s = s.replace(/\"/g,""");
s = s.replace(/\n/g,"
"); return s; } //解码 function html_decode(str) { var s = ""; if (str.length == 0) return ""; s = str.replace(/>/g,"&"); s = s.replace(//g,"\n"); return s; }
原文链接:https://www.f2er.com/jquery/41548.html"); return s; } //解码 function html_decode(str) { var s = ""; if (str.length == 0) return ""; s = str.replace(/>/g,"&"); s = s.replace(//g,"\n"); return s; }