Latest web development tutorials

HTML DOM 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對象