當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。