Clicking a disabled input or button

后端 未结 9 1430
星月不相逢
星月不相逢 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 13:55

    You can't without a workaround, see: jQuery detect click on disabled submit button

    The browsers disable events on disabled elements.

    Edited to add context from link:

    The asker found this thread with an explanation of why the events aren't registering: http://www.webdeveloper.com/forum/showthread.php?t=186057

    Firefox, and perhaps other browsers, disable DOM events on form fields that are disabled. Any event that starts at the disabled form field is completely canceled and does not propagate up the DOM tree. Correct me if I'm wrong, but if you click on the disabled button, the source of the event is the disabled button and the click event is completely wiped out. The browser literally doesn't know the button got clicked, nor does it pass the click event on. It's as if you are clicking on a black hole on the web page.

    The workaround would be style the button to "look" disabled, while not actually being so.

提交回复
热议问题