我有一个文本框readonly="readonly"
这意味着我无法编辑它。但我想要的是当用户双击该文本框时使其可编辑。
我已经尝试过的是:
<input size="10" readonly="readonly" ondblclick="setEditable(this)"/>
在 JavaScript 中:
function setEditable(i){
i.readonly = false;
}
但这不起作用。所以当用户双击文本框时,如何使文本框可编辑(只读)?
Update:
要再次使其只读:
var el = document.getElementById('txt');
el.onblur = function(){
this.setAttribute('readonly');
};
你可以这样做:
<input size="10" readonly="readonly" id="txt" />
JS:
var el = document.getElementById('txt');
el.ondblclick = function(){
this.removeAttribute('readonly');
};
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)