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