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


HTML DOM Strong用法及代码示例


HTML DOM中的Strong Object用于表示HTML <strong>元素。此标签用于显示文本的重要性。可以使用getElementById()方法访问strong元素。

用法:

document.getElementById("id")

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

范例1:

<!DOCTYPE html>  
<html>  
    <head> 
        <title> 
            HTML DOM Strong Object 
        </title> 
    </head> 
      
    <body style = "text-align:center;">  
  
        <h1 style = "color:green;">  
            GeeksForGeeks  
        </h1>  
          
        <h2>DOM strong Object</h2>  
          
        <!-- Assigne id to STRONG tag-->
        <p> 
            <strong id = "GFG">  
                GeeksForGeeks:
            </strong>  
            A computer science portal for geeks. 
        </p> 
          
        <button onclick = "myGeeks()"> 
            Submit 
        </button>  
          
        <!-- set style to the strong object -->
        <script>  
            function myGeeks() {  
                var para = document.getElementById("GFG");  
  
                /* Change the color of strong element */ 
                para.style.color = "green";  
            }  
        </script>  
    </body>  
</html>                    

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



范例2:可以使用document.createElement方法创建Strong Object。

<!DOCTYPE html>  
<html>  
    <head> 
        <title> 
            HTML DOM Strong Object 
        </title> 
    </head> 
      
    <body style = "text-align:center;">  
  
        <h1 style = "color:green;" >  
            GeeksForGeeks  
        </h1>  
          
        <h2>DOM strong Object</h2>  
          
        <button onclick = "myGeeks()"> 
            Submit 
        </button><br> 
          
        <!-- script to display strong element -->
        <script>  
            function myGeeks() {  
                var elem = document.createElement("STRONG");  
                var txt =  
                document.createTextNode("GeeksForGeeks:"  
                +"A computer science portal for geeks.");  
  
                elem.appendChild(txt);  
  
                document.body.appendChild(elem);  
            }  
        </script>  
    </body>  
</html>                    

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




相关用法


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