admin管理员组文章数量:1355107
Is it possible to set "readonly" attribute of an input to keep it editable?
I'm doing a crossword and I can change my function to search for/select a tag using different attribute but I'm still wondering if it is possible.
Thanks for help in advance!
Is it possible to set "readonly" attribute of an input to keep it editable?
I'm doing a crossword and I can change my function to search for/select a tag using different attribute but I'm still wondering if it is possible.
Thanks for help in advance!
Share Improve this question asked Jun 13, 2012 at 8:42 DamianS1987DamianS1987 3121 gold badge3 silver badges13 bronze badges 2- 3 Huh? You want to make something readonly to make it editable? This doesn't make sense. – PeeHaa Commented Jun 13, 2012 at 8:44
- if i get you right you could use some additional class to mark fields which are not empty. or take a look at html5demos./contenteditable property – shershen Commented Jun 13, 2012 at 8:49
3 Answers
Reset to default 6If the JavaScript readOnly
property is set to true
(a boolean, not a string), then the control will not be editable.
If the JavaScript readOnly
property is set to false
(a boolean, not a string), then the control will be editable.
If the HTML readonly
attribute is present, then the readOnly
property will default to true
.
If the HTML readonly
attribute is not present, then the readOnly
property will default to false
.
JavaScript can modify the value
property of a control no matter what state the readOnly
property has.
There is no way for a control to be edited through the normal browser UI if it is set to readOnly
(JavaScript consoles and DOM inspectors are not the normal UI).
The attribute readonly
renders the input control noneditable for a user. Using javascript you can still change its value. Setting the readonly
attribute in javascript to false
has no effect for the user, the input still will be readonly
. Removing the attribute will render the input editable for the user again.
You could also use the disabled
attribute, with two differences: the field is displayed grayed out, and you can set the disabled
attribute directly.
It's all tested/demonstrated in this jsfiddle [note: updated]
I suggest using the html5 supported data- prefix data-readonly="true" https://developer.mozilla/en-US/docs/Web/Guide/HTML/Using_data_attributes
本文标签: javascriptset readonly attribute to keep the input editableStack Overflow
版权声明:本文标题:javascript - set readonly attribute to keep the input editable - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743988548a2571712.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论