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

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

WBOY
Release: 2023-08-27 13:37:06
forward
962 people have browsed it

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>
Copy after login

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!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template