Event on a disabled input

前端 未结 10 2454
攒了一身酷
攒了一身酷 2020-11-21 15:53

Apparently a disabled is not handled by any event

Is there a way to work around this issue ?



        
10条回答
  •  粉色の甜心
    2020-11-21 15:53

    Disabled elements don't fire mouse events. Most browsers will propagate an event originating from the disabled element up the DOM tree, so event handlers could be placed on container elements. However, Firefox doesn't exhibit this behaviour, it just does nothing at all when you click on a disabled element.

    I can't think of a better solution but, for complete cross browser compatibility, you could place an element in front of the disabled input and catch the click on that element. Here's an example of what I mean:

    jq:

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

    Example: http://jsfiddle.net/RXqAm/170/ (updated to use jQuery 1.7 with prop instead of attr).

提交回复
热议问题