jQuery event.metaKey属性

jQuery event.metaKey属性

jQuery中的event.metaKey属性是用来识别元键是否被按下的。下面有两个例子讨论。
语法:

event.metaKey

返回值:如果键是元键,它返回 “true”,否则返回 “false”。

例子1:在这个例子中,输入<input>元素,看看结果。

<!DOCTYPE HTML>
<html>
  
<head>
    <title>
        jQuery event.metaKey Property
    </title>
  
    <script src=
"https://code.jquery.com/jquery-3.5.0.js">
    </script>
</head>
  
<body style="text-align:center;">
  
    <h1 style="color:green;">
        GeeksForGeeks
    </h1>
      
    <p id="GFG_UP"></p>
  
    <input type="text" 
        onkeydown="Geeks(event)" />
  
    <p id="GFG_DOWN"></p>
  
    <script>
        var elUp = document.getElementById("GFG_UP");
        var elDown = document.getElementById("GFG_DOWN");
        elUp.innerHTML = "JQuery | event.metaKey property";
  
        function Geeks(event) {
            if (event.metaKey) {
                elDown.innerHTML = 
                    "The META key was pressed!";
            } else {
                elDown.innerHTML = 
                    "The META key was NOT pressed!";
            }
        } 
    </script>
</body>
  
</html>

输出:
jQuery event.metaKey属性

例子2:从文件的任何地方按下任何按钮,并看到结果。

<!DOCTYPE HTML>
<html>
  
<head>
    <title>
        JQuery event.metaKey Property
    </title>
  
    <script src=
"https://code.jquery.com/jquery-3.5.0.js">
    </script>
</head>
  
<body style="text-align:center;">
  
    <h1 style="color:green;">
        GeeksForGeeks
    </h1>
      
    <p id="GFG_UP"></p>
  
    <p id="GFG_DOWN"></p>
  
    <script>
        var elUp = document.getElementById("GFG_UP");
        var elDown = document.getElementById("GFG_DOWN");
        elUp.innerHTML = "JQuery | event.metaKey property";
          
        $('html').click(function (event) {
            if (event.metaKey) {
                elDown.innerHTML = 
                    "The META key was pressed!";
            } else {
                elDown.innerHTML = 
                    "The META key was NOT pressed!";
            }
        }); 
    </script>
</body>
  
</html>

输出:
jQuery event.metaKey属性

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程