JS捕获按键事件的

JS捕获按键事件的

 1  < html >
 2    < script language = " javascript " >  
 3  function  test() 
 4 
 5  if (event.keyCode == 13 )
 6   { 
 7  alert( " 你按了回车 " )
 8   } 
 9  if (event.shiftKey == true )
10   {
11   alert( " 你按了shift "
12 
13  if (event.ctrlKey == true
14 
15  alert( " 你按了ctrl " )
16   }
17    if (event.altKey == true )
18   {
19   alert( " 你按了alt "
20  }
21   }
22 
23    </ script >  
24  < body onkeydown = " test() " >  
25  Please type  " enter " key  " shift " key  " ctrl " key  " alt " key.
26 
27    </ body  >
28 
29    </ html >
30 
31 

你可能感兴趣的:(JS捕获按键事件的)