1、添加处理方法:
/******************************************* * Description: * 禁止输入危险字符,如"'"、"/"、""和"&"。 * * Author: * Creator Liu *******************************************/ $.fn.replaceOther = function () { this.bind("keypress", function (e) { var keyCode = e ? e.which : event.keyCode; if (keyCode == 60 || keyCode == 62) { return false; } }); this.bind("dragenter", function () { return false; }); this.bind("keyup", function () { var s = this.value; if (s.indexOf("'") != -1 || s.indexOf("/") != -1 || s.indexOf("\") != -1 || s.indexOf("&") != -1) this.value = s.replace(new RegExp("[\&,\\,\/,\']", "gm"), ""); }); this.bind("blur", function () { var s = this.value; if (s.indexOf("'") != -1 || s.indexOf("/") != -1 || s.indexOf("\") != -1 || s.indexOf("&") != -1) this.value = s.replace(new RegExp("[\&,\\,\/,\']", "gm"), ""); }); };
2、添加属性关联:
//文本框去除危险字符 $(".txtBodyCheck").replaceOther();
e.g:(直接在Calss里面添加属性即可)
<asp:TextBox ID="txtCode" CssClass="textbox txtBodyCheck" runat="server"></asp:TextBox>