Disabled Text Input with onclick

2019-02-25 07:43发布

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

3条回答
家丑人穷心不美
2楼-- · 2019-02-25 08:20

How 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 comment it and I'll make an explanation.

查看更多
The star\"
3楼-- · 2019-02-25 08:27

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");
}
查看更多
Lonely孤独者°
4楼-- · 2019-02-25 08:37

You are probably lookinf for this:-

$("div").click(function (evt) {
    $(this).hide().prev("input[disabled]").prop("disabled", false).focus();
});

DEMO JSFIDDLE

查看更多
登录 后发表回答