當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


jQuery event.metaKey用法及代碼示例


event.metaKeyjQuery 中的屬性用於識別元鍵是否被按下。下麵討論兩個例子。
用法:

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> 

輸出:

示例 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> 

輸出:



相關用法


注:本文由純淨天空篩選整理自PranchalKatiyar大神的英文原創作品 jQuery event.metaKey Property。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。