Javascript javascript启用双击输入
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11320692/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
javascript enable input on double click
提问by Umbrella
I have a form with some inputs disabled. I want these inputs to be enabled when double clicked. Unfortunately, JS events seem not to fire on disabled inputs.
我有一个禁用了某些输入的表单。我希望在双击时启用这些输入。不幸的是,JS 事件似乎不会在禁用的输入上触发。
<input type="text" value="asdf" disabled="disabled" ondblclick="this.disabled=false;">?
Is there a way around this limitation?
有没有办法绕过这个限制?
Or am I just going to have to wrap any affected input in a span to house the event?
或者我是否只需要将任何受影响的输入包装在一个跨度中以容纳事件?
回答by JonWarnerNet
ondblclick
does not get fired on a disabled
element, you should mark it as readonly
:
ondblclick
不会在disabled
元素上触发,您应该将其标记为readonly
:
<input type="text" value="asdf" readonly="true" ondblclick="this.readOnly='';">