HTML DOM Input Month 对象

Month 对象

Month 对象是 HTML5 中的新对象。

Month 对象表示 HTML <input type="month"> 元素。

注释:Internet Explorer 或 Firefox 不支持 <input type="month"> 元素。

访问 Month 对象

您可以通过使用 getElementById() 来访问 <input type="month"> 元素:

var x = document.getElementById("myMonth");

亲自试一试

提示:您也可以通过遍历表单的 elements 集合 来访问 Month 对象。

创建 Month 对象

您可以通过使用 document.createElement() 方法来创建 <input type="month"> 元素:

var x = document.createElement("INPUT");
x.setAttribute("type", "month");

亲自试一试

Month 对象属性

属性描述
autocomplete设置或返回 month 字段的 autocomplete 属性值。
autofocus设置或返回 month 字段在页面加载后是否应自动获取焦点。
defaultValue设置或返回 month 字段的默认值。
disabled设置或返回 month 字段是否被禁用。
form返回对包含 month 字段的表单的引用。
list返回对包含 month 字段的 datalist 的引用。
max设置或返回 month 字段的 max 属性值。
min设置或返回 month 字段的 min 属性值。
name设置或返回 month 字段的 name 属性值。
readOnly设置或返回 month 字段是否是只读的。
required设置或返回在提交表单之前是否必须填写 month 字段。
step设置或返回 month 字段的 step 属性值。
type返回 month 字段的表单元素类型。
value设置或返回 month 字段的 value 属性值。

Input Month 对象方法

方法描述
select()选择 month 文本字段的内容。
stepDown()按指定数字递减 month 字段的值。
stepUp()按指定数字递增 month 字段的值。

标准属性和事件

Month 对象支持标准属性事件

相关页面

HTML 教程:HTML 表单

HTML 参考手册:HTML <input> 标签

HTML 参考手册:HTML <input> type 属性