查询的数据中存在特殊字符或者js语句,如:数据库字段中有一个字段的内容是: "alert(商品编码);",那么这个字段查出来到表格中之后,页面会弹出提示框
2.grid查询的字段来自于用户手动输入的文本,如果有恶意攻击,直接输入js语句,会执行相关语句。
表格字段formatter 的时候调用 HTMLEncode
{field:dlAddress,title:使用地点,width: 200,align:center,
formatter : function(value, row, index) {
return HTMLEncode(value);
}
}
/*—————————————————————————————–*\
* 函数: 把特殊字符进行转换
* 参数: value — 需要转化的字符串
* 返回值:
* 描述:
\*—————————————————————————————–*/
function HTMLEncode(value) {
var returnValue;
if(value==null){
return null;
}
returnValue = value.replace(/&/g, &);
returnValue = returnValue.replace(/</g, <);
returnValue = returnValue.replace(/>/g, >);
returnValue = returnValue.replace(/\n\n/g, <br/>);
returnValue = returnValue.replace(/\r\r/g, <br/>);
returnValue = returnValue.replace(/\n/g, <br/>);
returnValue = returnValue.replace(/\r/g, <br/>);
returnValue = returnValue.replace(/\t/g, );
return returnValue;
如果觉得《jquery填充table时怎么处理特殊字符 – CSS – 前端 css5个td合并》对你有帮助,请点赞、收藏,并留下你的观点哦!