Input Text readOnly attribute
Definition and Usage
readOnly
The attribute sets or returns whether the text field is read-only.
You cannot modify a read-only field. However, users can select, highlight it, and copy text from it.
Tip:If you want to prevent users from interacting with the field, use disabled attribute.
See also:
HTML Reference Manual:Attribut readonly de l'élément <input> HTML
Example
Example 1
Set the text field to read-only:
document.getElementById("myText").readOnly = true;
Example 2
Check if the text field is read-only:
var x = document.getElementById("myText").readOnly;
Syntax
Return the readOnly attribute:
textObject.readOnly
Set the readOnly attribute:
textObject.readOnly = true|false
attribute value
value | description |
---|---|
true|false |
Définit si le champ de texte doit être en lecture seule
|
Détails techniques
Valeur de retour : | Valeur booléenne, renvoie si le champ de texte est en lecture seule true sinon retourne false . |
---|
Compatibilité du navigateur
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Support | Support | Support | Support | Support |