问题:捕获document对象的keydown事件,再通过调用document.writeln函数输出当前按键
思路1:捕获keydown事件,然后从该事件的which属性中获得当前按键Unicode格式的键码
- window.onload=function{
- if ( document.addEventListener ){
- document.addEventListener( "keydown", getKey , false );
- }else if ( document.attachEvent ){
- document.attachEvent( "keydown" getKey );
- }
- }
- function getKey( event ){
- var theEvent = event ? event : window.event;
- document.writeln ( theEvent.which );
- }
复制代码 |
|