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


HTML DOM Underline用法及代码示例


DOM下划线对象用于表示HTML <u>元素。下划线元素由getElementById()访问。

用法:

document.getElementById("id"); 

其中‘id’是分配给<u>标记的ID。

范例1:

<!DOCTYPE html>  
<html>  
    <head> 
        <title> 
            HTML DOM underline Object 
        </title> 
    </head> 
      
    <body style = "text-align:center;">  
      
        <h1 style = "color:green;" >  
            GeeksForGeeks  
        </h1>  
          
        <h2>DOM underline Object</h2>  
  
        <p><u id = "u">GeeksforGeeks!</u> A computer 
        science portal for geeks.</p> 
          
        <button onclick = "Geeks()"> 
            Click Here! 
        </button> 
          
        <script> 
            function Geeks() { 
                var txt = document.getElementById("u"); 
                txt.style.color = "green"; 
            } 
        </script> 
    </body>  
</html>                    

输出:
在单击按钮之前:
underline
单击按钮后:
underline



范例2:可以使用document.createElement方法创建下划线对象。

<!DOCTYPE html>  
<html>  
    <head> 
        <title> 
            HTML DOM underline Object 
        </title> 
    </head> 
      
    <body style = "text-align:center"> 
           
        <h1 style = "color:green;" >  
            GeeksForGeeks  
        </h1>  
          
        <h2>DOM underline Object</h2>  
  
        <button onclick = "Geeks()"> 
            Click Here! 
        </button> 
          
        <p id = "p"></p> 
          
        <script> 
            function Geeks() { 
                var txt = document.createElement("U"); 
                var t = document.createTextNode("An underlined text."); 
                txt.appendChild(t); 
                document.getElementById("p").appendChild(txt); 
            } 
        </script> 
    </body>  
</html>                    

输出:
在单击按钮之前:
underline
单击按钮后:
underline




相关用法


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