[英]How to make textarea with readonly=false editable?
I have a form and a textarea field in it.我有一个表单和一个 textarea 字段。 I need to make it editable, and I don't know how.
我需要使它可编辑,但我不知道如何。
<textarea id="note" class="input" type="text" name="note">Suggest changes</textarea>
When I inspect elements, its readonly attribute is already false, but it won't let me change anything.当我检查元素时,它的 readonly 属性已经是 false,但它不会让我改变任何东西。
I've tried:我试过了:
document.getElementsByTagName("textarea")[0].readonly = false;
$("#note").prop('readonly', false);
$("#note").removeAttr('readonly');
None of those help.这些都没有帮助。
The problem is here问题就在这里
document.getElementsByTagName("textarea")[0].readonly = false;
It should be它应该是
document.getElementsByTagName("textarea")[0].readOnly = "false";
Or also in your case或者在你的情况下
document.getElementById("note").readOnly = "false";
我明白了, element.removeAttribute('readonly')
有效,但我只尝试过 Firefox。
尝试
$("#note").attr("readonly", false);
我遇到了同样的问题并用这个解决了它:
document.getElementById("note").removeAttribute('readonly')
The problem really is the use of the wrong case, readonly
should be written in camel case ie 'readOnly', so this should work.问题确实是使用了错误的大小写,
readonly
应该写在骆驼大小写中,即“readOnly”,所以这应该有效。
document.getElementsByTagName("textarea")[0].readOnly = false;
https://www.w3schools.com/jsref/prop_textarea_readonly.asp https://www.w3schools.com/jsref/prop_textarea_readonly.asp
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.