Latest web development tutorials

HTML DOM Input Time readOnly 屬性

Input Time 對象參考手冊 Input Time對象

實例

設置time 字段為只讀:

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

輸出結果:


嘗試一下»

定義和用法

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

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

該屬性反映了HTML readonly 屬性。

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


瀏覽器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

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

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


語法

返回readOnly 屬性:

timeObject .readOnly

設置readOnly 屬性:

timeObject .readOnly=true|false

屬性值

描述
true|false 描述了time 字段是否只讀
  • true - time 字段為只讀
  • false - 默認。 time 字段不是只讀

技術細節

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


更多實例

實例

查看time字段是否為只讀:

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

嘗試一下»


相關頁面

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


Input Time 對象參考手冊 Input Time對象