Input Month值屬性用於設置或返回Month字段的value屬性的值。輸入月份值屬性可用於為“星期”字段指定月份和年份。
用法:
- 要返回value屬性:monthObject.value 
- 設置value屬性:monthObject.value = YYYY-MM 
屬性值:
- YYYY-MM:該值表示年份和月份。此處YYYY是年份,即2019,而MM是月份,即03。
返回值:它返回一個表示月份字段值的字符串。
以下示例程序旨在說明“月值”屬性:
示例1:本示例返回Input Month值屬性。
<!DOCTYPE html>  
<html>  
  
<head>  
    <title>  
        HTML DOM Input Month value Property 
    </title>  
</head>  
  
<body style="text-align:center;">  
  
    <h1>GeeksForGeeks</h1>  
  
    <h2>DOM Input Month value Property</h2>  
            <form id="myGeeks"> 
    <input type="month" id="month_id" name="geeks" value="2019-03">  
                 </form> 
                 <br> 
    <button onclick="myGeeks()">Click Here!</button>  
      
    <p id="GFG" style="font-size:20px;"></p>  
      
    <!-- Script to return the value Property-->
    <script>  
        function myGeeks() {  
            var gfg = document.getElementById("month_id").value; 
            document.getElementById("GFG").innerHTML = gfg; 
        }  
    </script>  
</body>  
  
</html>                     輸出
在單擊按鈕之前:

單擊按鈕後:

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

單擊按鈕後:

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