IE下可以用window.event物件,或是event物件偵測按鍵。但Netscape、Firefox不行。不過NS,FF確實是有event物件的,只是不是全域物件:
<script>function fxn (e) { if(e.shiftKey) .... }</script>
<a href="javascript:void(0);" onclick="fxn(event)">
上面這段程式碼在IE及FF上都是可以運作的。 
屬性的使用可以參考下表:


性質 描述


altKey, ctrlKey, shiftKey
這是 布林值,用來偵測是否當鍵盤事件發生時 Alt, Ctrl, Meta 與 Shift 鍵是按著的


metaKey
這是 布林值,用來偵測是否 Meta 按鍵被按下  只支援 NS/Firefox


charCode
指出按下按鍵的 Unicode 碼,使用 String.fromCharCode(charCode) 將其轉為字串。 只支援 NS/Firefox


keycode
指出按下按鍵的 Unicode 碼,使用 String.fromCharCode(keyCode)將其轉為字串。


type
用來代表 event 事件的字串,如:"mouseover", "click" 等.


which
Legacy
property indicating the Unicode for the key pressed. Identical
to "charCode", except this property works in NS4 as well. NS/Firefox only.


方向鍵:左﹐上﹐右﹐下分別是 event.keyCode值:37﹐38﹐39﹐40
event.keycode==13代表Enter鍵
event.keycode==32代表空白鍵
event.keycode==27代表Esc鍵
event.keycode==16代表Shift鍵
event.keycode==17代表Ctrl鍵
event.keycode==18代表Alt鍵
A-Z分別是65~90
 
文章標籤

ASTRUE 發表在 痞客邦 留言(0) 人氣(6,856)