javascript 如何使 readonly=false 的 textarea 可编辑?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27312717/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to make textarea with readonly=false editable?
提问by DR_
I have a form and a textarea field in it. I need to make it editable, and I don't know how.
我有一个表单和一个 textarea 字段。我需要使它可编辑,但我不知道如何。
<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.
这些都没有帮助。
回答by cesar_sr91
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";
回答by apexik
I see, the element.removeAttribute('readonly')
works, but I tried only firefox yet.
我明白了,这些element.removeAttribute('readonly')
作品,但我还只尝试过 Firefox。
回答by Bhumi Shah
Try
尝试
$("#note").attr("readonly", false);