我有一个带有 readonly="readonly" 的文本框,这意味着我无法对其进行编辑.但我想要的是让这个文本框在用户双击它时可编辑.
I've a textbox with readonly="readonly" that means I can not edit it. But what I want is to make this textbox editable when user double clicks on it.
我尝试过的是:
<input size="10" readonly="readonly" ondblclick="setEditable(this)"/>
在 JavaScript 中:
and in JavaScript:
function setEditable(i){
i.readonly = false;
}
但这不起作用.那么当用户双击文本框时,我怎样才能使文本框可编辑,它是只读的?
But this does not worked. So how can I make a textbox editable, which is readonly, when user double clicks on it?
更新:
再次使其只读:
var el = document.getElementById('txt');
el.onblur = function(){
this.setAttribute('readonly');
};
<小时>
你可以这样做:
You can do this:
<input size="10" readonly="readonly" id="txt" />
JS:
var el = document.getElementById('txt');
el.ondblclick = function(){
this.removeAttribute('readonly');
};
这篇关于使用 JavaScript 使文本框可编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
检查一个多边形点是否在传单中的另一个内部Check if a polygon point is inside another in leaflet(检查一个多边形点是否在传单中的另一个内部)
更改传单标记群集图标颜色,继承其余默认 CSSChanging leaflet markercluster icon color, inheriting the rest of the default CSS properties(更改传单标记群集图标颜色,继承其余默认
触发点击传单标记Trigger click on leaflet marker(触发点击传单标记)
如何更改 LeafletJS 中的默认加载磁贴颜色?How can I change the default loading tile color in LeafletJS?(如何更改 LeafletJS 中的默认加载磁贴颜色?)
将 Leaflet 图层控件添加到侧边栏Adding Leaflet layer control to sidebar(将 Leaflet 图层控件添加到侧边栏)
Leaflet - 在弹出窗口中获取标记的纬度和经度Leaflet - get latitude and longitude of a marker inside a pop-up(Leaflet - 在弹出窗口中获取标记的纬度和经度)