我已经使用“只读”属性的文本框,使文本框不可编辑,我可以知道如何禁用只读属性点击按钮。我们可以使用任何脚本来做到这一点吗?禁用只读文本框onclicking按钮
<input type="text" name="" value="" readonly="readonly"/><br/>
<input type="submit" name="" value="update" onclick="" />
我已经使用“只读”属性的文本框,使文本框不可编辑,我可以知道如何禁用只读属性点击按钮。我们可以使用任何脚本来做到这一点吗?禁用只读文本框onclicking按钮
<input type="text" name="" value="" readonly="readonly"/><br/>
<input type="submit" name="" value="update" onclick="" />
你可以做两件事情:
readonly
(不区分大小写)属性,使用removeAttribute
readOnly
(案敏感)财产至false
HTML:
<input id="myInput" type="text" readonly="readonly" /><br />
<input id="myButton" type="submit" value="update" />
JS(选项1):[Demo]
document.getElementById('myButton').onclick = function() {
document.getElementById('myInput').removeAttribute('readonly');
};
JS(选项2):[Demo]
document.getElementById('myButton').onclick = function() {
document.getElementById('myInput').readOnly = false;
};
非常感谢! – Anand
好吧,要简单!你可以使用jQuery去除这个属性(jQuery会很简单,你也可以使用JS来做到这一点)。下面是该代码:
$('input[type=submit]').click(function() {
$('input[type=text]').removeAttr('readonly');
})
需要设置的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="submit"
的jQuery或JavaScript '类型= “按钮”',你有什么用? – Satpal