altKey 事件属性

定义和用法

altKey 事件属性返回一个布尔值。指示在指定的事件发生时,Alt 键是否被按下并保持住了。

语法

  1. event.altKey=true|false|1|0

实例

下面的例子可提示当鼠标按键被点击时 "ALT" 键是否已被按住:

  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. function isKeyPressed(event)
  5. {
  6. if (event.altKey==1)
  7. {
  8. alert("The ALT key was pressed!")
  9. }
  10. else
  11. {
  12. alert("The ALT key was NOT pressed!")
  13. }
  14. }
  15. </script>
  16. </head>
  17.  
  18. <body onmousedown="isKeyPressed(event)">
  19.  
  20. <p>Click somewhere in the document.
  21. An alert box will tell you if you
  22. pressed the ALT key or not.</p>
  23.  
  24. </body>
  25. </html>