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


HTML <label> form屬性用法及代碼示例


HTML <label>表單屬性用於指定<label>元素可以包含一個或多個表單。

用法:

<label form="form_id"> 

屬性值:它包含單個值form_id,該值包含值,即form_id,該值指定一個或多個label元素所屬。此屬性的值應為<form>元素的ID。


例:

<!DOCTYPE html>  
<html>  
    <head>  
        <title>  
            HTML label form Attribute  
        </title>  
    </head>  
      
    <body style = "text-align:center">  
          
        <h1 style = "color:green;">  
            GeeksforGeeks  
        </h1>  
          
        <h2>  
            HTML label form Attribute  
        </h2>  
          
        <form action="#" method="get" id="GFG_form"> 
            <!-- Starts label tag from here -->
            <label for = "student">  
                Student  
            </label>  
              
            <input type = "radio" name = "Occupation"
            id = "student" value = "student"><br>  
      
            <label for = "business">  
                Business  
            </label>  
              
            <input type = "radio" name = "Occupation"
            id = "business" value = "business"><br>  
        </form> 
          
        <label for="other" form="GFG_form">Other</label> 
    </body>  
      
</html>                    

輸出:

支持的瀏覽器:<label>表單屬性支持的瀏覽器如下:

  • 穀歌瀏覽器
  • IE瀏覽器
  • Firefox
  • Safari
  • Opera


相關用法


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