Input Text readOnlyProperty

Input Text 对象参考手册Input Text Object

Example

Set the text field to read-only:

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

Try it Yourself »


Definition and Usage

The readOnly property sets or returns whether a text field is read-only.

Read-only fields cannot be modified. However, users can still tab to the field, and can select or copy its text.

Tip:To protect user interaction fields, use thedisabledattribute instead.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

All major browsers support the readOnly property.


Syntax

Return the readOnly property:

textObject.readOnly

Set the readOnly property:

textObject.readOnly=true|false

Property Values

Value Description
true|false  Specifies whether the text field is read-only
  • true - The text field is read-only
  • false - Default. The text field can be modified.

Technical Details

Return value: A Boolean value, returns true if the text field is read-only, otherwise returns false.


More Examples

Example

Check if the text field is read-only:

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

xThe result is:

true

Try it Yourself »


Related Pages

HTML Reference Manual:HTML <input> readonly attribute


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