Javascript .which是什么东西?....新手请教

Home Home
引用 | 编辑 racekid
2008-08-10 23:08
楼主
推文 x0

图 1.
附上美女图以兹答谢!

请问一下个位专家,
这是个测试onkeypress的程式,
onkeypress的时候,执行数字不能输入,
这个code里面的.which是有什么功能?
我在网上和书上好像都找不到这个keyword的功能?
这好像也不太像是个keyword???表情




复制程式
<html>
<body>
<script type="text/javascript">
function noNumbers(e)
{
var keynum;
var keychar;
var 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>
Type some text (numbers not allowed):
<input type="text" onkeypress="return noNumbers(event)" />
</form>

</html>



献花 x0
引用 | 编辑 andyz
2008-08-12 00:18
1楼
  
which
Two meanings
1) For the key events
Returns the code of the pressed key. a = 65 etc.

2) For the mouse events
Returns the mouse button pressed
1 - Left button
2 - Middle button
3 - Right button

献花 x0