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


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。