Input Number readOnlyProperty

Input Number 对象参考手册Input Number Object

Examples

Set the number field to read-only:

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

Output result:


Try it yourself »

Definition and Usage

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

Read-only fields 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 usedisabledattribute instead.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the readOnly property.

Note:Internet Explorer 9 and earlier IE versions do not support <input> elements with the type="number" attribute.


Syntax

Return the readOnly property:

numberObject.readOnly

Set the readOnly property:

numberObject.readOnly=true|false

Property Values

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

Technical Details

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


More Examples

Examples

Check whether the number field is read-only:

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

Try it yourself »


Related Pages

HTML Reference Manual:HTML <input> readonly attribute


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