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


SVG AElement.href屬性用法及代碼示例

SVG AElement.href屬性返回與給定A元素的屬性相對應的SVGAnimatedLength對象

用法:

AElement.href

返回值:該屬性返回可以使用的SVGAnimatedLength對象獲取AElement的href。

範例1:

<!DOCTYPE html> 
<html> 
  
<body> 
    <svg viewBox="0 0 100 100" 
        xmlns="http://www.w3.org/2000/svg"> 
          
        <!-- A link around a shape -->
        <a href="https://www.geeksforgeeks.org" id="gfg"> 
            <circle cx="20" cy="40" r="15" /> 
        </a> 
          
        <script> 
            var g = document.getElementById("gfg"); 
            console.log(g.href); 
        </script> 
    </svg> 
</body> 
  
</html>

輸出:



範例2:

<!DOCTYPE html> 
<html> 
  
<body> 
    <svg viewBox="0 0 100 100" 
        xmlns="http://www.w3.org/2000/svg"> 
          
        <!-- A link around a text -->
        <a href="https://www.geeksforgeeks.org" id="gfg"> 
            <text x="40" y="20" text-anchor="middle"> 
                <gfg> 
            </text> 
        </a> 
          
        <script> 
            var g = document.getElementById("gfg"); 
            console.log(g.href); 
        </script> 
    </svg> 
</body> 
  
</html>

輸出:

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




相關用法


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