Input Time readOnly attribute

Definition and usage

readOnly Attribute sets or returns whether the input field should be read-only.

You cannot modify read-only fields. However, users can select, highlight it, and copy text from it.

This property reflects the HTML readonly attribute.

Tip:If you want to prevent users from interacting with the field, please use disabled attribute.

See also:

HTML Reference Manual:HTML <input> readonly-Eigenschaft

Instance

Example 1

Set the time field to read-only:

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

Try it yourself

Example 2

Check if the time field is read-only:

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

Try it yourself

Syntax

Return readOnly attribute:

timeObject.readOnly

Set readOnly attribute:

timeObject.readOnly = true|false

Attribute value

Value Description
true|false

Specify whether the time field should be read-only.

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

Technical details

Return value: Boolean value, if the time field is read-only, it returns truewird zurückgegeben, sonst false.

Browser-Unterstützung

Die Zahlen in der Tabelle weisen auf die erste Browser-Version hin, 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

Beachten Sie:Das Element <input type="time"> wird in Firefox nicht als任何时间字段显示。