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


SVG Event.isTrusted屬性用法及代碼示例

SVG Event.isTrusted屬性是一個布爾值,當事件由用戶操作生成時為true。

用法:

var eventIsTrusted = event.isTrusted

返回值:此屬性返回事件元素的布爾值。

範例1:在此示例中,我們將使用onclick事件。

<!DOCTYPE html> 
<html> 
  
<body> 
    <svg viewBox="0 0 1000 1000" 
        xmlns="http://www.w3.org/2000/svg"> 
          
        <circle cx="50" cy="50" r="50" 
            onclick="check(event)" /> 
          
        <script type="text/javascript"> 
            function check(event) { 
                document.write( 
                    "This Event is Trusted:",  
                    event.isTrusted); 
            } 
        </script> 
    </svg> 
</body> 
  
</html>

輸出:



範例2:在此示例中,我們將使用onclick事件。

<!DOCTYPE html> 
<html> 
  
<body> 
    <svg viewBox="0 0 1000 1000" 
        xmlns="http://www.w3.org/2000/svg"> 
          
        <text x="50" y="20" font-size="20px" 
            onclick="check(event)"> 
            GeeksForGeeks 
        </text> 
          
        <script type="text/javascript"> 
            function check(event) { 
                document.write( 
                    "This Event is Trusted:",  
                    event.isTrusted); 
            } 
        </script> 
    </svg> 
</body> 
  
</html>

輸出:

範例3:在此示例中,我們將使用onmouseover事件。

<!DOCTYPE html> 
<html> 
  
<body> 
    <svg viewBox="0 0 1000 1000" 
        xmlns="http://www.w3.org/2000/svg"> 
          
        <circle cx="50" cy="50" r="50" 
            onmouseover="check(event)" /> 
          
        <script type="text/javascript"> 
            function check(event) { 
                document.write( 
                    "This Event is Trusted:",  
                    event.isTrusted); 
            } 
        </script> 
    </svg> 
</body> 
  
</html>

輸出:

範例4:在此示例中,我們將使用onmouseover事件。

<!DOCTYPE html> 
<html> 
  
<body> 
    <svg viewBox="0 0 1000 1000" 
        xmlns="http://www.w3.org/2000/svg"> 
          
        <text x="50" y="20" font-size="20px" 
            onmouseover="check(event)"> 
            GeeksForGeeks 
        </text> 
          
        <script type="text/javascript"> 
            function check(event) { 
                document.write( 
                    "This Event is Trusted:",  
                    event.isTrusted); 
            } 
        </script> 
    </svg> 
</body> 
  
</html>

輸出:




相關用法


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