Input Datetime readOnly attribute

Definition and usage

readOnly Sets or returns whether the date-time field should be read-only.

Read-only fields cannot be modified. However, users can select, highlight it, and copy text from it.

This property reflects the HTML readonly attribute.

Tip:To prevent users from interacting with the field, use disabled attribute.

See also:

HTML Reference Manual:HTML <input> readonly-Eigenschaft

Example

Example 1

Set the date-time field to read-only:

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

Try it yourself

Example 2

Check if the date-time field is read-only:

var x = document.getElementById("myDatetime").readOnly;

Try it yourself

Syntax

Return the readOnly property:

datetimeObject.readOnly

Set the readOnly property:

datetimeObject.readOnly = true|false

Attribute value

Value Description
true|false

Specify whether the date-time field should be read-only

  • true - The date-time field is read-only
  • false - Default. The date-time field is not read-only

Technical details

Return value: Boolean value, returned if the date-time field is read-only true; Otherwise return false.

Browserunterstützung

Die in der Tabelle genannten Zahlen beziehen sich auf die erste Version des Browsers, die diese Eigenschaft vollständig unterstützt.

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Unterstützt 10.0 Unterstützt Unterstützt Unterstützt

Beachtung:Das <input type="datetime">-Element zeigt in allen gängigen Browsern außer Safari keine Datums- und Zeitfelder/Kalender an.