Event on a disabled input

前端 未结 10 2455
攒了一身酷
攒了一身酷 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 16:05

    We had today a problem like this, but we didn't wanted to change the HTML. So we used mouseenter event to achieve that

    var doThingsOnClick = function() {
        // your click function here
    };
    
    $(document).on({
        'mouseenter': function () {
            $(this).removeAttr('disabled').bind('click', doThingsOnClick);
        },
        'mouseleave': function () {
            $(this).unbind('click', doThingsOnClick).attr('disabled', 'disabled');
        },
    }, 'input.disabled');
    

提交回复
热议问题