Latest web development tutorials

HTML DOM Input Number readOnly property

Input Number Object Reference Input Number Object

Examples

Set number field is read-only:

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

Output:


try it"

Definition and Usage

readOnly property sets or returns the number field is read-only.

Read-only fields can not be modified. But you can copy the contents of the field.

This property reflects the HTML readonly attribute.

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


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support readOnly property.

Note: Internet Explorer 9 and earlier versions of IE do not support the use of type = "number" <input> element attributes.


grammar

Back readOnly attributes:

numberObject .readOnly

Set readOnly properties:

numberObject .readOnly=true|false

Property Value

描述
true|false 描述了 number 字段是否只读
  • true - true - number 字段为只读
  • false - 默认。 number 字段不是只读

technical details

return value: Boolean value that, if the number is read-only field returns true, otherwise returns false.


More examples

Examples

Check number field is read-only:

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

try it"


Related Pages

HTML Reference Manual: HTML <the INPUT> Readonly property


Input Number Object Reference Input Number Object