HTML DOM中的Input Month required屬性用於設置或返回在提交表單時是否應填寫Input Month字段。此屬性用於反映HTML必需屬性。
用法:
- 它返回Input Month required屬性。monthObject.required 
- 它用於設置“輸入月份”必填屬性。monthObject.required = true|false 
屬性值:
- true:它指定在提交表單之前必須填寫“月”字段。
- false:它是默認值。它指定在提交表單之前不得填寫“月”字段。
返回值:它返回一個布爾值,該值表示在提交表單之前必須填寫月字段。
示例1:本示例返回Input Month required屬性。
<!DOCTYPE html>  
<html>  
  
<head>  
    <title>  
        HTML DOM Input Month required Property 
    </title>  
</head>  
  
<body style="text-align:center;">  
  
    <h1>GeeksForGeeks</h1>  
  
    <h2>DOM Input Month required Property</h2>  
            <form id="myGeeks"> 
    <input type="month" id="month_id" name="geeks" required>  
                 </form> 
                 <br> 
    <button onclick="myGeeks()">Click Here!</button>  
      
    <p id="GFG" style="font-size:20px;"></p>  
      
    <!-- Script to return the required Property-->
    <script>  
        function myGeeks() {  
            var gfg = document.getElementById("month_id").required; 
            document.getElementById("GFG").innerHTML = gfg; 
        }  
    </script>  
</body>  
  
</html>                     輸出
在單擊按鈕之前:

單擊按鈕後:

示例2:本示例說明了如何設置屬性。
<!DOCTYPE html>  
<html>  
  
<head>  
    <title>  
        HTML DOM Input Month required Property 
    </title>  
</head>  
  
<body style="text-align:center;">  
  
    <h1>GeeksForGeeks</h1>  
  
    <h2>DOM Input Month required Property</h2>  
            <form id="myGeeks"> 
    <input type="month" id="month_id" name="geeks" required>  
                </form> 
                <br> 
    <button onclick="myGeeks()">Click Here!</button>  
      
    <p id="GFG" style="font-size:20px;"></p>  
      
    <!-- Script to set the required Property-->
    <script>  
        function myGeeks() {  
            var gfg = document.getElementById("month_id"); 
            gfg.required = false; 
            var g =    gfg.required;         
            document.getElementById("GFG").innerHTML =  
                        "The value is changed from true to " + g; 
        }  
    </script>  
</body>  
  
</html>                    輸出:
在單擊按鈕之前:

單擊按鈕後:

支持的瀏覽器:下麵列出了DOM輸入支持的瀏覽器所需的月屬性。
- 穀歌瀏覽器
- Internet Explorer 10.0以上
- Firefox
- Opera
- Safari
注意:在Firefox中,輸入類型=“ month”元素不顯示任何日期字段或日曆。
相關用法
- HTML Input Month max用法及代碼示例
- HTML Input Month value用法及代碼示例
- HTML Input Month name用法及代碼示例
- HTML Input Month min用法及代碼示例
- HTML Input Month readOnly用法及代碼示例
- HTML Input Month disabled用法及代碼示例
- HTML Input Month type用法及代碼示例
- HTML Input Month form用法及代碼示例
- HTML Input Month autofocus用法及代碼示例
- HTML Input Month defaultValue用法及代碼示例
- HTML Input Month autocomplete用法及代碼示例
- HTML Input Month step用法及代碼示例
- HTML Input URL required用法及代碼示例
- HTML Input Time required用法及代碼示例
- HTML Input Text required用法及代碼示例
注:本文由純淨天空篩選整理自ManasChhabra2大神的英文原創作品 HTML | DOM Input Month required Property。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
