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


HTML Legend form用法及代碼示例


DOM圖例表單屬性用於返回對包含<legend>標記的表單的引用。這是隻讀屬性,成功時將返回表單對象。

用法:

legendObject.form

例:本示例返回一個表單屬性。


<!DOCTYPE html> 
<html> 
  
<head> 
    <title>DOM Legend form Property</title> 
    <style> 
        form { 
            width:50%; 
        } 
          
        label { 
            display:inline-block; 
            float:left; 
            clear:left; 
            width:90px; 
            margin:5px; 
            text-align:left; 
        } 
          
        input[type="text"] { 
            width:250px; 
            margin:5px 0px; 
        } 
          
        .gfg { 
            font-size:40px; 
            color:green; 
            font-weight:bold; 
        } 
    </style> 
</head> 
  
<body> 
    <div class="gfg">GeeksforGeeks</div> 
    <h2>DOM Legend Form Property</h2> 
    <form id="myGeeks"> 
        <fieldset> 
            <!-- Assigning legend id -->
            <legend id="GFG">STUDENT::</legend> 
            <label>Name:</label> 
            <input type="text"> 
            <br> 
            <label>Email:</label> 
            <input type="text"> 
            <br> 
            <label>Date of birth:</label> 
            <input type="text"> 
            <br> 
            <label>Address:</label> 
            <input type="text"> 
            <br> 
            <label>Enroll No:</label> 
            <input type="text"> 
        </fieldset> 
    </form> 
    <br> 
    <button onclick="myGeeks()">Submit</button> 
    <p id="sudo" style="font-size:25px;"></p> 
    <script> 
        function myGeeks() { 
  
            // Accessing legend tag  
            var g =  
                document.getElementById("GFG").form.id; 
            
            document.getElementById( 
              "sudo").innerHTML = g; 
        } 
    </script> 
</body> 
  
</html>

輸出:

在單擊按鈕之前:

單擊按鈕後:

支持的瀏覽器:

  • 穀歌瀏覽器
  • 火狐瀏覽器
  • Edge
  • Opera
  • Safari


相關用法


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