Input Date readOnly 屬性

Input Date 對象參考手冊 Input Date 對象

實例

設置 date 字段為只讀:

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

輸出結果:



定義和用法

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

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

該屬性反映了 HTML readonly 屬性。

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


流覽器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

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

注意:Internet Explorer 或 Firefox 流覽器不支持 <input type="date"> 元素。


語法

返回 readOnly 屬性:

inputdateObject.readOnly

設置 readOnly 屬性:

inputdateObject.readOnly=true|false

屬性值

描述
true|false 描述了date字段是否只讀:
  • true - date 字段是只讀的
  • false - 默認。 date 字段不是只讀的。

技術細節

返回值: 布爾值,如果 date 字段是只讀的返回 true,否則返回false。


更多實例

實例

查看 date 字段是否只讀:

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



相關文章

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


Input Date 對象參考手冊 Input Date 對象