javascript encode或者decode html

function myHTMLEnCode(str)
{
var s = "";
if (str.length == 0) return "";
s = str.replace(/&/g, "&");
s = s.replace(/</g, "&lt;");
s = s.replace(/>/g, "&gt;");
s = s.replace(/ /g,"&nbsp;");
s = s.replace(/\'/g, "'");
s = s.replace(/\"/g, "&quot;");
//s = s.replace(/\n/g, "<br>");
return s;  
}
function myHTMLDeCode(str)
{
var s="";
if(str.length ==0) return "";
s = str.replace(/&amp;/g, "&");
s = s.replace(/&lt;/g, "<");
s = s.replace(/&gt;/g, ">");
s = s.replace(/&nbsp;/g, " ");
s = s.replace(/'/g, "\'");
s = s.replace(/&quot;/g, "\"");
s = s.replace(/<br>/g, "\n");
return s; 
}

上一篇:采用keepalived施工可用性MySQL-HA


下一篇:$.ajax函数调接口,报异常No converter found for return value of type: class java.util.ArrayList