codecamp

HTML DOM Input DatetimeLocal readOnly 属性

Input DatetimeLocal readOnly 属性

Input DatetimeLocal 对象参考手册 Input DatetimeLocal 对象

实例

设置本地时间字段为只读:

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

输出结果:


尝试一下 »

定义和用法

readOnly 属性用于设置或者返回本地时间字段是否为只读。

只读字段不能修改。但是可以复制该字段的内容。

该属性反映了 HTML readonly 属性。

提示: 为了确保表单数据的准确性,可以使用 disabled 属性替代。


浏览器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

The readOnly property 所有主流浏览器都支持

注意:Internet Explorer 或 Firefox 浏览器不支持 <input type="datetime-local"> 元素。


语法

返回 readOnly 属性:

datetimelocalObject.readOnly

设置 readOnly 属性:

datetimelocalObject.readOnly=true|false

属性值

描述
true|false 描述了本地时间字段是否只读
  • true - 本地时间字段为只读
  • false - 默认。本地时间字段不是只读

技术细节

返回值: 布尔值,如果本地时间字段为只读返回true,否则返回 false。


更多实例

实例

查看本地时间字段是否为只读:

var x = document.getElementById("myLocalDate").readOnly;
x输出结果为:
true

尝试一下 »


相关页面

HTML 参考手册: HTML <input> readonly 属性


Input DatetimeLocal 对象参考手册 Input DatetimeLocal 对象
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

HTML DOM对象

HTML DOM 引用对象

HTML DOM Password 对象

HTML DOM Link 对象

HTML DOM Select 对象

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }