js过滤html函数
发布时间:01/15 来源: 浏览:
关键词:
我们能利用js过滤html标签的也只过滤常用的如& < > '"这类字符,把它们替换成html编码如& <等这类的函数
function encodehtmlfortext(text){
text = text.replace(new regexp("&","gm"),"&");
text = text.replace(new regexp("<","gm"),"<");
text = text.replace(new regexp(">","gm"),">");
text = text.replace(new regexp("'","gm"),"'");
text = text.replace(new regexp(""","gm"),""");
return text;
}
反过来函数
function encodehtmlforurl(url){
url = url.replace(new regexp("<","gm"),"<");
url = url.replace(new regexp(">","gm"),">");
url = url.replace(new regexp("'","gm"),"'");
url = url.replace(new regexp(""","gm"),""");
return url;
}