对输入框的非法字符进行转译,来起到阻止输入<><>等非法字符的效果
window.onload = function(){//防止输入标签,造成跨域攻击
let tags = document.querySelectorAll("input");
for(let i=0;i<tags.length;i++){
tags[i].onblur = function(){
this.value = htmlEncode(this.value)
console.log(this.value)
}
}
}
let htmlEncode = function(str) {
var div = document.createElement("div");
div.appendChild(document.createTextNode(str));
return div.innerHTML;
}