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


SVG localName屬性用法及代碼示例

SVG localName屬性返回給定Attr元素的localName。

用法:

name = attribute.localName

返回值:此屬性返回Attr的localName。

範例1:

HTML

<!DOCTYPE html> 
<html> 
  
<body> 
    <svg viewBox="0 0 100 100" 
        xmlns="http://www.w3.org/2000/svg"> 
          
        <!-- A link around a text -->
        <text id="example" x="20" y="20"> 
            Click me 
        </text> 
          
        <script> 
            const element = document 
                .querySelector("#example"); 
  
            const attribute = element.attributes[0]; 
  
            console.log('LocalName is:',  
                    attribute.localName); 
        </script> 
    </svg> 
</body> 
  
</html>

輸出:




範例2:

HTML

<!DOCTYPE html> 
<html> 
  
<body> 
    <svg viewBox="0 0 100 100" 
        xmlns="http://www.w3.org/2000/svg"> 
          
        <!-- A link around a shape -->
        <circle class="gfg" cx="20" 
            cy="20" r="15"> 
            Click me 
        </circle> 
          
        <script> 
            const element = document.querySelector(".gfg"); 
            const attribute = element.attributes[0]; 
            console.log('LocalName is:', attribute.localName); 
        </script> 
    </svg> 
</body> 
  
</html>

輸出:


參考:https://developer.mozilla.org/en-US/docs/Web/API/Attr/localName




相關用法


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