js動態創建svg與use 使用iconfont symbol


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="./iconfont/iconfont.css">
    
</head>
<body>

 <!-- <svg class="icon svg-icon" aria-hidden="true">
                  <use xlink:href="#icon1"></use>
                </svg> -->
    <script src="./iconfont/iconfont.js"></script>
    <script>
        let svgns = "http://www.w3.org/2000/svg";
      let xlinkns = "http://www.w3.org/1999/xlink";
        let icon = document.createElementNS(svgns, "svg");
        icon.setAttribute("aria-hidden", true);
        let use = document.createElementNS(svgns, "use");
        use.setAttributeNS(xlinkns, "href", "#icon1");
        icon.appendChild(use);
        document.body.appendChild(icon)
    </script>
    
</body>
</html>

 

 希望對你們有幫助!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM