当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


HTML DOM Abbreviation用法及代码示例


DOM缩写对象用于表示HTML <abbr>元素。缩写元素由getElementById()访问。

范例1:

<!DOCTYPE html> 
<html> 
    <head> 
        <title> 
            HTML DOM Abbreviation Object 
        </title> 
          
        <script> 
            function myGeeks() { 
                var abbr = document.getElementById("sudo").title; 
                document.getElementById("geeks").innerHTML = abbr; 
            } 
        </script> 
    </head> 
      
    <body> 
        <h2>DOM Abbreviation Object</h2> 
          
        <abbr id = "sudo" title="GeeksforGeeks"> 
            GFG 
        </abbr><br><br> 
          
        <button onclick = "myGeeks()"> 
            Submit 
        </button> 
          
        <p id = "geeks"></p> 
    </body> 
</html>                    

输出:
在单击按钮之前:

单击按钮后:

范例2:可以使用document.createElement方法创建缩写对象。

<!DOCTYPE html> 
<html> 
    <head> 
        <title> 
            HTML DOM Abbreviation Object 
        </title> 
          
        <!-- script for Abbreviation Object -->
        <script> 
            function myGeeks() { 
                var w = document.createElement("ABBR"); 
                var f = document.createTextNode("GFG"); 
                w.setAttribute("title", "GeeksforGeeks"); 
                w.appendChild(f); 
                document.getElementById("sudo").appendChild(w); 
            } 
        </script> 
    </head> 
      
    <body> 
        <h2>DOM Abbreviation Object</h2> 
          
        <button onclick = "myGeeks()"> 
            Submit 
        </button> 
  
        <p id = "sudo"></p> 
          
    </body> 
</html>                    

输出:
之前单击按钮:

单击按钮后:

支持的浏览器:下面列出了DOM缩写对象支持的浏览器:

  • 谷歌浏览器
  • IE浏览器
  • Firefox
  • Opera
  • Safari




相关用法


注:本文由纯净天空筛选整理自ManasChhabra2大神的英文原创作品 HTML | DOM Abbreviation Object。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。