防止用户提交带有恶意的脚本

作者:简简单单 2008-06-16

//编码HTML  和  解码Html。
//在评论的时候为了防止用户提交带有恶意的脚本,可以先过滤HTML标签,过滤掉双引号,单引号,符号&,符号<,符号
用法:




**************/

        String.prototype.htmlEncode=function(){
    return this.replace(/&/g,"&").replace(//g,">").replace(/\"/g,""").replace(/\'/g,"'");
}
        String.prototype.htmlDecode=function(){
    return this.replace(/\&\;/g, '\&').replace(/\>\;/g, '\>').replace(/\<\;/g, '\<').replace(/\"\;/g, '\'').replace(/\&\#39\;/g, '\'');
}

相关文章

精彩推荐