JavaScript中shiftKey鼠标事件的作用是什么?


shiftkey鼠标事件属性用于显示在鼠标按钮单击时是否按下SHIFT键。

示例

你可以尝试运行以下代码以了解如何在JavaScript中实现shiftKey 鼠标事件。

<!DOCTYPE html>
<html>
   <body onmousedown = "funcShiftKey(event)">
      <div>Press and hold SHIFT key and then click here.</div>
      <script>
         function funcShiftKey(event) {
            if (event.shiftKey) {
               alert("SHIFT key: Pressed");
            } else {
               alert("SHIFT key: NOT Pressed");
            }
         }
      </script>
   </body>
</html>

更新于: 2020年5月23日

160 次浏览

开启您的职业

完成课程并通过认证

开始学习
广告
© . All rights reserved.