Clicking a disabled input or button

后端 未结 9 1432
星月不相逢
星月不相逢 2020-11-28 13:12

Is it possible to click on a disabled button and provide some feedback to the user?

HTML:


         


        
9条回答
  •  粉色の甜心
    2020-11-28 14:03

    There is no way to capture a click on disabled elements. Your best bet is to react to a specific class on the element.

    HTML Markup:

    
    

    JavaScript code:

    $('input').click(function (event) {
        if ($(this).hasClass('disabled')) {
            alert('CLICKED, BUT DISABLED!!');
        } else {
            alert('Not disabled. =)');
        }
    });
    

    You could then use CSS styling to simulate a disabled look:

    .disabled
    {
        background-color: #DDD;
        color: #999;
    }
    

    Here's a jsFiddle demonstrating its use.

提交回复
热议问题