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


HTML checked屬性用法及代碼示例


HTML中的checked屬性用於指示在頁麵加載時是否應檢查元素。它是一個布爾屬性。

注意:它隻能與類型為“checkbox”或“radio”的<input>元素一起使用。

用法:

<input type = "checkbox|radio" checked>

範例1:

<!DOCTYPE html> 
<html> 
    <head> 
        <title>HTML checked Attribute</title> 
    </head> 
    <body style = "text-align:center;"> 
        <h1 style = "color:green;">GeeksforGeeks</h1> 
        <h2>HTML checked Attribute</h2> 
        <form > 
            <!-- Below input elements have attribute "checked" -->
            <input type="checkbox" name="check" value="1" checked> 
                                             Checked by default<br> 
            <input type="checkbox" name="check" value="2"> 
                                  Not checked by default<br> 
        </form> 
    </body> 
</html>                    

輸出:
checked



範例2:

<!DOCTYPE html> 
<html> 
    <head> 
        <title>HTML checked Attribute</title> 
    </head> 
    <body style = "text-align:center;"> 
        <h1 style = "color:green;">GeeksforGeeks</h1> 
        <h2>HTML checked Attribute</h2> 
        <form > 
            <!-- Below input elements have attribute "checked" -->
            <input type="radio" name="check" value="1" checked> 
                                         Selected by default<br> 
            <input type="radio" name="check" value="2"> 
                              Not selected by default<br> 
        </form> 
    </body> 
</html>                    

輸出:
checked

支持的瀏覽器:選中的屬性支持的瀏覽器如下:

  • 穀歌瀏覽器1.0
  • Internet Explorer 2.0
  • Firefox 1.0
  • Opera 1.0
  • 蘋果Safari 1.0




相關用法


注:本文由純淨天空篩選整理自Vishal Chaudhary 2大神的英文原創作品 HTML | checked Attribute。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。