是否按下 shift 键?

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <script>
  5. function isKeyPressed(event) {
  6. var text = "切换键未被按下!";
  7. if (event.shiftKey == 1) {
  8. text = "切换键被按下了!";
  9. }
  10. document.getElementById("demo").innerHTML = text;
  11. }
  12. </script>
  13. </head>
  14.  
  15. <body>
  16.  
  17. <img src ="/i/eg_planets.jpg" alt="Planets"
  18. onmousedown="isKeyPressed(event)" />
  19.  
  20. <p>点击上面的图片,会提示您是否按下了 shift 键。</p>
  21.  
  22. <p id="demo"></p>
  23.  
  24. </body>
  25. </html>