我对文本框使用了" readonly“属性,这使得文本框不可编辑,我可以知道如何在单击按钮时禁用readonly属性。我们可以使用任何脚本来做到这一点吗?
<input type="text" name="" value="" readonly="readonly"/><br/>
<input type="submit" name="" value="update" onclick="" />发布于 2014-02-07 00:55:01
你可以做两件事:
false
的readOnly (区分大小写)属性删除readOnly(不区分大小写)属性
HTML:
<input id="myInput" type="text" readonly="readonly" /><br />
<input id="myButton" type="submit" value="update" />JS (选项1):[]
document.getElementById('myButton').onclick = function() {
document.getElementById('myInput').removeAttribute('readonly');
};JS (选项2):[]
document.getElementById('myButton').onclick = function() {
document.getElementById('myInput').readOnly = false;
};发布于 2014-02-07 00:54:13
好吧,简单点说!您可以使用jQuery删除此属性(jQuery会很简单,您也可以使用JS来完成此操作)。下面是实现该功能的代码:
$('input[type=submit]').click(function () {
$('input[type=text]').removeAttr('readonly');
})发布于 2014-02-07 00:55:37
需要将元素的readOnly属性设置为false
您可以使用document.getElementById(),它通过元素的ID引用元素
HTML,在这里我向元素添加了id
<input type="text" id="myTextBox" name="" value="" readonly="readonly"/><br/>
<input type="submit" id="myButton" name="" value="update" />JavaScript,在这里您可以看到readOnly属性为false。
document.getElementById('myButton').onclick = function() {
document.getElementById('myTextBox').readOnly =false;
};此外,我建议您使用'type="button"'而不是type="submit"
https://stackoverflow.com/questions/21609012
复制相似问题