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上都是可以運作的。
屬性的使用可以參考下表:
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
