最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to make textarea with readonly=false editable? - Stack Overflow

programmeradmin3浏览0评论

I have a form and a textarea field in it. 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.

I've tried:

document.getElementsByTagName("textarea")[0].readonly = false;
$("#note").prop('readonly', false);
$("#note").removeAttr('readonly');

None of those help.

I have a form and a textarea field in it. 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.

I've tried:

document.getElementsByTagName("textarea")[0].readonly = false;
$("#note").prop('readonly', false);
$("#note").removeAttr('readonly');

None of those help.

Share Improve this question asked Dec 5, 2014 at 9:33 DR_DR_ 1741 gold badge2 silver badges14 bronze badges 4
  • disabled attribute? – u_mulder Commented Dec 5, 2014 at 9:34
  • By default, a textarea is editable. So you must have made something that make it uneditable. Please show us what. – blue112 Commented Dec 5, 2014 at 9:35
  • post a fiddle of your code. try using $('#note').attr('readonly',false); – Aditya Commented Dec 5, 2014 at 9:37
  • 1 Im pretty sure, somewhere in your code you turned it disabled. Because by default a <textarea> is editable. – azhpo Commented Dec 5, 2014 at 9:38
Add a comment  | 

5 Answers 5

Reset to default 5

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";

Try

$("#note").attr("readonly", false); 

I see, the element.removeAttribute('readonly') works, but I tried only firefox yet.

I had the same problem and solved it with this:

document.getElementById("note").removeAttribute('readonly')

The problem really is the use of the wrong case, readonly should be written in camel case i.e 'readOnly', so this should work.

document.getElementsByTagName("textarea")[0].readOnly = false;

https://www.w3schools.com/jsref/prop_textarea_readonly.asp

发布评论

评论列表(0)

  1. 暂无评论