How to trigger a click event on disabled elements

后端 未结 5 937
难免孤独
难免孤独 2021-01-11 23:18

I have a disabled button, which is enabled after checking \"I accept terms and conditions\" checkbox. The problem is that I wanted to trigger an alert, if a user cli

5条回答
  •  日久生厌
    2021-01-11 23:58

    Disabled elements doesn't trigger any mouse events at all, so that's probably a lost cause.

    However, when clicking a parent element, the event.target seems to be given correctly, which means this should work :

    $(document).on('click', function (e) {   
        if (e.target.id == 'subm_tc') {
            if($("#modlgn-tc").is(':checked')){
                 alert('checked');
            } else {
                 alert('unchecked');
            }
        }
    });
    

    FIDDLE

提交回复
热议问题