HTML DOM Input Month 物件


HTML DOM input month 物件表示 type=”month” 的 <input> 元素。

讓我們建立一個 input month 物件 -

語法

以下是語法 -

var monthInput = document.createElement(“INPUT”);
monthInput.setAttribute(“type”,”month”);

屬性

以下是 HTML DOM input month 物件的屬性 -

屬性解釋
autocomplete它返回並更改月份輸入欄位的 autocomplete 屬性值。
autofocus它返回並修改頁面載入時是否應使月份輸入欄位獲得焦點。
disabled它返回並修改月份輸入欄位是否被停用。
defaultValue它返回並更改月份輸入欄位的預設值。
form它返回包含 HTML 文件中月份輸入欄位的表單的引用。
list它返回包含月份輸入欄位的資料列表的引用。
max它返回並修改月份輸入欄位的 max 屬性值。
min它返回並修改月份輸入欄位的 min 屬性值。
name它返回並更改月份輸入欄位的 name 屬性值。
readOnly它返回並修改月份輸入欄位是否為只讀。
required它返回並修改在提交表單之前是否必須填寫月份欄位。
step它返回並更改月份輸入欄位的 step 屬性值。
type它返回月份輸入欄位的 type 屬性值。
value它返回並修改月份輸入欄位的 value 屬性內容。

方法

以下是 HTML DOM input month 物件的方法

方法解釋
stepUp()它根據其引數中指定的值遞增月份輸入欄位的值。
stepDown()它根據其引數中指定的值遞減月份輸入欄位的值。

示例

讓我們看看 HTML DOM input month 物件的示例 -

 即時演示

<!DOCTYPE html>
<html>
<head>
<style>
   body{
      text-align:center;
      background-color:#fff;
      color:#0197F6;
   }
   h1{
      color:#23CE6B;
   }
   .btn{
      background-color:#fff;
      border:1.5px dashed #0197F6;
      height:2rem;
      border-radius:2px;
      width:60%;
      margin:2rem auto;
      display:block;
      color:#0197F6;
      outline:none;
      cursor:pointer;
   }
</style>
</head>
<body>
<h1>DOM Input month Object Example</h1>
<button onclick="createMonthField()" class="btn">Create an input month field</button>
<script>
   function createMonthField() {
      var monthInput = document.createElement("INPUT");
      monthInput.setAttribute("type", "month");
      monthInput.setAttribute("value", "2019-07");
      document.body.appendChild(monthInput);
   }
</script>
</body>
</html>

輸出

這將產生以下輸出 -

點選“建立月份輸入欄位”按鈕以生成月份輸入欄位 -

更新於: 2019-07-30

105 次檢視

啟動你的 職業生涯

透過完成課程獲得認證

開始學習
廣告

© . All rights reserved.