Input Date readOnlyProperty

Input Date 对象参考手册Input Date Object

Example

Set the date field to read-only:

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

Output:


Try it Yourself »

Definition and Usage

The readOnly property is used to return or set whether the date field is read-only.

A read-only field cannot be modified. However, the content of the field can be copied.

This property reflects the HTML readonly attribute.

Tip:To ensure the accuracy of form data, you can use thedisabledproperty instead.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the readOnly property.

Note:Internet Explorer or Firefox browsers do not support the <input type="date"> element.


Syntax

Return the readOnly property:

inputdateObject.readOnly

Set the readOnly property:

inputdateObject.readOnly=true|false

Property Values

Value Description
true|false Describes whether the date field is read-only:
  • true - The date field is read-only
  • false - Default. The date field is not read-only.

Technical Details

Return Value: A Boolean value, returning true if the date field is read-only, otherwise returning false.


More Examples

Example

Check whether the date field is read-only:

var x = document.getElementById("myDate").readOnly;
xThe output result is:
true

Try it Yourself »


Related Articles

HTML Reference Manual:HTML <input> readonly Attribute


Input Date 对象参考手册Input Date Object Other Extensions