&nb"/> &nb">

Home  >  Article  >  Web Front-end  >  What does the shiftKey attribute in keyboard events do in JavaScript?

What does the shiftKey attribute in keyboard events do in JavaScript?

WBOY
WBOYforward
2023-08-27 13:37:06931browse

What does the shiftKey attribute in keyboard events do in JavaScript?

The altkey attribute is used to display whether the SHIFT key was pressed when the key event was triggered.

Example

You can try running the following code to learn how to implement the shiftKey property in JavaScript.

<!DOCTYPE html>
<html>
   <body>
      <input type = "text" onkeydown = "funcShiftKey(event)">
      <div id = "res">Press any key</div>
      <script>
         function funcShiftKey(event) {
            var val = document.getElementById("res");
            if (event.shiftKey) {
               val.innerHTML = "SHIFT key: Pressed";
            } else {
               val.innerHTML = "SHIFT key: NOT Pressed";
            }
         }
      </script>
   </body>
</html>

The above is the detailed content of What does the shiftKey attribute in keyboard events do in JavaScript?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete