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


HTML isTrusted Event用法及代碼示例


isTrusted事件屬性用於檢查事件是否受信任。

返回值:如果事件受信任,則返回True,否則返回false。

用法:


event.isTrusted

以下示例程序旨在說明isTrusted事件屬性:

例:找出特定事件是否受信任。

<!DOCTYPE html> 
<html> 
  
<head> 
    <title>isTrusted Event Property in HTML</title> 
    <style> 
        h1 { 
            color:green; 
        } 
          
        h2 { 
            font-family:Impact; 
        } 
          
        body { 
            text-align:center; 
        } 
    </style> 
</head> 
  
<body onclick="MyEvent(event)"> 
  
    <h1>GeeksforGeeks</h1> 
    <h2>isTrusted Event Property</h2> 
  
    <p>Double Click the "Check Event" 
       button to check whether the event  
       is trusted or not.</p> 
  
    <button ondblclick="MyEvent(event)"> 
      Try it 
    </button> 
  
    <script> 
        // Check whether the event is trusted or not. 
        function MyEvent(event) { 
            if ("isTrusted" in event) { 
                if (event.isTrusted) { 
                    alert("The " + event.type +  
                    " is a trusted event."); 
                } else { 
                    alert("The " + event.type +  
                    " is not a trusted event."); 
                } 
            } else { 
                alert("Your browser does not support " 
                       +"the isTrusted property"); 
            } 
        } 
    </script> 
  
</body> 
  
</html>

輸出:
在單擊按鈕之前:

單擊按鈕後:

支持的瀏覽器:

  • Opera
  • IE瀏覽器
  • 穀歌瀏覽器
  • Firefox


相關用法


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