HTML DOM 中的Input Month 对象用于表示具有 type=”month”属性的 HTML 输入元素。可以使用 getElementById() 方法访问具有 type=”month”属性的输入元素。
句法:
- 它用于访问具有 type=”month” 属性的 元素。
document.getElementById("id");
- 它用于创建具有 type=”month” 属性的 元素。
document.createElement("input");
属性值:
Property | Description |
---|---|
type | This property is used to return the type of form element of the month field. |
value | This property is used to set or return the value of the value attribute of a month field. |
autocomplete | This property is used to set or return the value of the autocomplete attribute of a month field. |
autofocus | This property is used to set or return whether a month field should automatically get focus when the page loads. |
defaultValue | This property is used to set or return the default value of a month field. |
disabled | This property is used to set or return whether a month field is disabled or not. |
form | This property is used to return reference to the form that contains the month field. |
list | This property is used to return a reference to the datalist that contains the month field. |
max | This property is used to set or return the value of the max attribute of a month field. |
min | This property is used to set or return the value of the min attribute of a month field. |
name | This property is used to set or return the value of the name attribute of a month field. |
placeholder | This property is used to set or return the value of the placeholder attribute of a month field. |
readOnly | This property is used to set or return whether the month field is read-only or not. |
required | This property is used to set or return whether the month field must be filled out before submitting a form. |
step | This property is used to set or return the value of the step attribute of a month field. |
输入月份对象方法:
Method | Description |
---|---|
stepDown() | This method is used to decrements the value of the input month by a specified number. |
stepUp() | This method is used to increment the value of the input month by a specified number. |
示例 1:此示例使用 getElementById() 方法访问具有 type=”month” 属性的 元素。
html
HTML DOM Input Month Object
GeeksforGeeks
DOM Input Month Object
html
HTML DOM Input Month Object
GeeksforGeeks
DOM Input Month Object
输出:
点击按钮前:
点击按钮后:
示例 2:此示例使用 document.createElement() 方法创建具有 type=”month” 属性的 元素。
html
HTML DOM Input Month Object
GeeksforGeeks
DOM Input Month Object
输出:
点击按钮前:
点击按钮后:
支持的浏览器:
- 谷歌浏览器
- Internet Explorer(IE 11 之后)
- 歌剧
- 苹果浏览器