event.keyCode与event.which

时间:2014-11-19 10:43:33   收藏:0   阅读:252
 
 
//Netscape/Firefox/Opera中不支持 window.event.keyCode,需要用event.which代替
//IE用event.keCode方法获取当前被按下的键盘按键值,
//而NetScape/FireFox/Opera用的则是event.which


例:
<html><body>
<script type="text/javascript">
function noNumbers(e){
var keynumvar keycharvar numcheck 
if(window.event) // IE{keynum = e.keyCode
}
else if(e.which) // Netscape/Firefox/Opera
{keynum = e.which}
keychar = String.fromCharCode(keynum)
numcheck = /d/return !numcheck.test(keychar)}
</script> 
<form>
<input type="text" onkeypress="return noNumbers(event)" />
</form></html>

 

原文:http://www.cnblogs.com/silentjesse/p/4107532.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!