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

如何用javaScript做判断?
功能要求:
        在键盘键如字符时要自动过滤 <> " "等这些特殊符号,我该怎么写?触发事件是什么啊?




------解决方案--------------------
onkeypress= "if (event.keyCode==60||event.keyCode==62) event.returnValue = false; "
------解决方案--------------------
用正则表达式,直接键盘键入用onkeyup触发,如果是粘贴则用onbeforepaste触发
如下例:把你要屏蔽的字符写在[]内。

<input type= "text " size= "20 " name= "cc " onkeyup= "value=value.replace(/[ <> ]/g, ' ') " onbeforepaste= "clipboardData.setData( 'text ',clipboardData.getData( 'text ').replace(/[ <> ]/g, ' ')) ">