admin管理员组文章数量:1188429
I have a textarea which is disabled by default. And then on press of 'Edit' I take some input from user. If it is valid, I want to enable the textarea. Here is the code which I have right now:
<textarea name="comment" cols="5" rows="2" disabled="true"><%= $tmp_com %></textarea>
<a href="javascript:validateUser()">Edit</a>
function validateUser(){
var name=prompt("Please enter the password");
if (name=="1234")
{
document.getElementByName("comment").disabled="false";
}
}
I have a textarea which is disabled by default. And then on press of 'Edit' I take some input from user. If it is valid, I want to enable the textarea. Here is the code which I have right now:
<textarea name="comment" cols="5" rows="2" disabled="true"><%= $tmp_com %></textarea>
<a href="javascript:validateUser()">Edit</a>
function validateUser(){
var name=prompt("Please enter the password");
if (name=="1234")
{
document.getElementByName("comment").disabled="false";
}
}
Share
Improve this question
edited Feb 24, 2021 at 23:08
Brian Tompsett - 汤莱恩
5,88372 gold badges61 silver badges133 bronze badges
asked Nov 30, 2012 at 2:09
Pi HorsePi Horse
2,4309 gold badges31 silver badges52 bronze badges
3 Answers
Reset to default 12There is no getElementByName in JavaScript. Easiest solution, add an id, and use getElementById.
<textarea name="comment" id="comment" cols="5" rows="2" disabled="true">
and JavaScript
document.getElementById("comment").disabled="false";
Its better for you to use id instead of name. Any way I'm using name here to follow the question.
<a href="javascript:validateUser()">Edit</a>
<textarea name="comment" cols="5" rows="2" disabled="disabled">aaaaa</textarea>
<script type="text/javascript">
function validateUser(){
var name=prompt("Please enter the password");
if (name=="1234")
document.getElementsByName("comment")[0].disabled=false;
}
</script>
Use jquery
$("[name='comment']").attr('disabled', true);
$("[name='comment']").attr('disabled', false);
or by Id
$("#comment").attr('disabled', true);
本文标签: javascriptEnabledisable textarea after taking input from keyboardStack Overflow
版权声明:本文标题:javascript - Enabledisable textarea after taking input from keyboard - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738395247a2084472.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论