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


SVG Element.attributes屬性用法及代碼示例

SVG Element.attributes屬性返回包含給定元素的所有屬性的對象。

用法:

var attr = element.attributes

返回值:此屬性返回一個包含元素所有屬性的對象。

範例1:

HTML

<!DOCTYPE html>  
<html>  
  
<body>  
    <svg width="350" height="350" 
        xmlns="http://www.w3.org/2000/svg"> 
        <a href="https://www.geeksforgeeks.org" id="gfg"> 
           <text x='100' y='100'>GfG</text> 
        </a> 
        <script> 
           var g = document.getElementById('gfg'); 
           console.log(g.attributes) 
        </script> 
    </svg> 
</body>  
  
</html>

輸出:



範例2:

HTML

<!DOCTYPE html>  
<html>  
  
<body>  
    <svg width="350" height="350" 
         xmlns="http://www.w3.org/2000/svg"> 
        <a href="https://www.geeksforgeeks.org" id="gfg"> 
            <circle cx='100' cy='100' r="80"></circle> 
        </a> 
        <script> 
            var g = document.getElementById('gfg'); 
            console.log(g.attributes) 
        </script> 
    </svg> 
</body>  
  
</html>

輸出:




相關用法


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