日期:2014-05-16  浏览次数:20417 次

怎样在文本框里输入的时候就屏蔽掉非法字符?
请教各位大哥大姐,怎样在文本框里在输入的时候,就可以屏蔽掉,特定的字符,比如javascript以及 <html> 这些标记型的字符(直接就不让输入的)?

------解决方案--------------------
屏蔽特定字符
<script>
function bind() {
var s = "abc ";
if (s.indexOf(String.fromCharCode(event.keyCode))> =0)
event.returnValue = false;

}
</script>
<input type=text value= " " onkeypress= "bind() ">

如果只是为了屏蔽html标记只要把 <和> 替换成&lt;和&gt;就好了

------解决方案--------------------
用正则吧