Latest web development tutorials

HTML DOM Input Month readOnly 屬性

Input Month 對象參考手冊 Input Month對象

實例

設置month 字段為只讀:

document.getElementById("myMonth").readOnly = true;

輸出結果:


嘗試一下»

定義和用法

readOnly 屬性用於設置或者返回month 字段是否為只讀。

只讀字段不能修改。 但是可以復制該字段的內容。

該屬性反映了HTML readonly 屬性。

提示:為了確保表單數據的準確性,可以使用disabled屬性替代。


瀏覽器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

所有主流瀏覽器都支持readOnly 屬性。

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


語法

返回readOnly 屬性:

monthObject .readOnly

設置readOnly 屬性:

monthObject .readOnly=true|false

屬性值

描述
true|false 描述了 month 字段是否只读
  • true - month 字段为只读
  • false - 默认。 month 字段不是只读

技術細節

返回值: 布爾值,如果month 字段為只讀返回true,否則返回false。


更多實例

實例

查看month 字段是否為只讀:

var x = document.getElementById("myMonth").readOnly;
x輸出結果為:
true

嘗試一下»


相關頁面

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


Input Month 對象參考手冊 Input Month對象