这里提供一个过滤非法脚本的函数: function RemoveXSS($val) { // remove all non-printable characters. CR(0a) and LF(0b) and TAB(9) are allowed // this prevents some character re-spacing such as <java\0script> // note that you have to handle splits with \n
转换原理:// 编码原理就是创建TextNode节点,附加到容器中,再取容器的innerHTML.(将脚本编码) // 解码原理是将字符串赋給容器的innerHTML,再取innerText或textContent(过滤掉js脚本). 1. 对特殊字符进行转义成html脚本符号 ///将字符串进行编码,将特殊字符转变为html语言 function htmlencode(s) { var div = document.createElement('div'); div.appendChild(d