是否按下 shift 键?
- <!DOCTYPE html>
- <html>
- <head>
- <script>
- function isKeyPressed(event) {
- var text = "切换键未被按下!";
- if (event.shiftKey == 1) {
- text = "切换键被按下了!";
- }
- document.getElementById("demo").innerHTML = text;
- }
- </script>
- </head>
- <body>
- <img src ="/i/eg_planets.jpg" alt="Planets"
- onmousedown="isKeyPressed(event)" />
- <p>点击上面的图片,会提示您是否按下了 shift 键。</p>
- <p id="demo"></p>
- </body>
- </html>