Latest web development tutorials

HTML DOM Input Month 對象

Input Month 對象

Input Month 對像是HTML5 新增的。

Input Month 對象表示使用type="month" 的HTML <input> 元素。

注意: Internet Explorer或Firefox瀏覽器不支持使用type="month"屬性的<input>元素。

訪問Input Month 對象

你可以使用getElementById() 函數來訪問使用type="month" 屬性的<input> 元素:

var x = document.getElementById("myMonth"); 嘗試一下

提示:你同樣可以通過表單的元素集合來訪問Input Month對象。

創建Input Month 對象

你可以使用document.createElement() 方法來創建使用type="month" 屬性的<input> 元素:

var x = document.createElement("INPUT");
x.setAttribute("type", "month"); 嘗試一下

Input 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對象同樣支持標準屬性事件


相關文章

HTML教程: HTML表單

HTML參考手冊: HTML <input>標籤

HTML參考手冊: HTML <input> type屬性