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


HTML input checkbox用法及代碼示例

HTML <input type =“ checkbox”>用於定義複選框字段。該複選框顯示為一個方形框,在激活該框時將其選中。它允許用戶在所有受限選項中選擇一個或多個選項。

用法:

<input type="checkbox"> 

例:

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

輸出:

支持的瀏覽器:

  • 穀歌瀏覽器
  • Firefox
  • Edge
  • Opera
  • 蘋果Safari




相關用法


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