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


HTML DOM Small用法及代码示例


HTML DOM中的Small Object用于表示HTML <small>元素。可以使用getElementById()方法访问该小元素。

用法:

document.getElementById("id"); 

将id分配给<small>标记的位置。

范例1:

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

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



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

<!DOCTYPE html>  
<html>  
    <head> 
        <title> 
            HTML DOM Small Object 
        </title> 
    </head>  
      
    <body style = "text-align:center">  
      
        <h1 style = "color:green;" >  
            GeeksForGeeks  
        </h1>  
          
        <h2>DOM small Object</h2>  
  
        <button onclick = "Geeks()"> 
            Click Here! 
        </button> 
          
        <br><br> 
          
        <div> 
            A <span id = "p"></span> portal for geeks. 
        </div> 
          
        <script> 
            function Geeks() { 
                var txt = document.createElement("SMALL"); 
                var t = document.createTextNode("computer science"); 
                txt.appendChild(t); 
                document.getElementById("p").appendChild(txt); 
            } 
        </script> 
    </body>  
</html>                    

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




相关用法


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