Input Date readOnly attribute
Definition and usage
readOnly
Attribute sets or returns whether the date field should be read-only.
You cannot modify the read-only field. However, users can select it, highlight it, and copy text from it.
This property reflects the HTML readonly attribute.
Tip:To prevent users from interacting with this field, use disabled attribute。
See also:
HTML Reference Manual:HTML <input> readonly 属性
Instance
Example 1
Set the date field to read-only:
document.getElementById("myDate").readOnly = true;
Example 2
Check if the date field is read-only:
var x = document.getElementById("myDate").readOnly;
Syntax
Return readOnly attribute:
inputdateObject.readOnly
Set readOnly attribute:
inputdateObject.readOnly = true|false
Attribute value
Value | Description |
---|---|
true|false |
Specify whether the date field should be read-only.
|
Technical details
Return value: | Boolean value, if the date field is read-only, it returns true ,否则返回 false 。 |
---|
浏览器支持
表中的数字注明了首个完全支持该属性的浏览器版本。
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
支持 | 10.0 | 支持 | 支持 | 支持 |
注意:<input type="date"> 元素在 IE11 及更早版本中不显示任何日期字段/日历。