admin管理员组文章数量:1401616
I need a way of capturing onclick, for a text input that is disabled. I would prefer not to use jQuery, but if there was no javascript alternative, would use it. Thanks in advance
EDIT: I have tried simply adding an onclick="" to a disabled text field, which did not work. Is there any way to do it without jquery? Thanks
I need a way of capturing onclick, for a text input that is disabled. I would prefer not to use jQuery, but if there was no javascript alternative, would use it. Thanks in advance
EDIT: I have tried simply adding an onclick="" to a disabled text field, which did not work. Is there any way to do it without jquery? Thanks
Share Improve this question edited Sep 15, 2013 at 20:13 user2370460 asked Sep 15, 2013 at 20:06 user2370460user2370460 7,84011 gold badges34 silver badges46 bronze badges 3-
textInput.onclick = function() { alert('Like this?') }
– tckmn Commented Sep 15, 2013 at 20:07 - @Doorknob Where should I put this code? Does it need jQuery? – user2370460 Commented Sep 15, 2013 at 20:15
- Just to clarify, jQuery is 101% JavaScript. – mikekavouras Commented Sep 16, 2013 at 2:00
3 Answers
Reset to default 5How about delegation events to parent elements like here?
<span style="position:relative;" onClick="event.target.value='clicked';">
<input type="text" disabled "/>
</span>
If my answer is acceptable please ment it and I'll make an explanation.
You are probably lookinf for this:-
$("div").click(function (evt) {
$(this).hide().prev("input[disabled]").prop("disabled", false).focus();
});
DEMO JSFIDDLE
This is the modified jsfiddle proposed by Rahul Tripathi using pure javascript.
This is the function that made it works:
document.getElementById("textInput").onclick = function() {
alert("Input clicked");
}
本文标签: javascriptDisabled Text Input with onclickStack Overflow
版权声明:本文标题:javascript - Disabled Text Input with onclick - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744319087a2600407.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论