jQuery prevent other events after a click

后端 未结 6 1017
谎友^
谎友^ 2020-12-14 07:15

I am trying to prevent multiple clicks on links and items, which is causing problems.

I am using jQuery to bind click events to buttons (jQuery UI) and image links (

6条回答
  •  南方客
    南方客 (楼主)
    2020-12-14 07:34

    You've got a couple of options:

    1. If your buttons/links will reload the page, you can simply unbind the click event handler:

      $('input:submit').click(fumction() {
          $(this).unbind('click');
          // Handle event here 
      })
      
    2. You can disable the buttons, and re-enable them once you're done (I think this should also work with ):

      $('input:submit').click(function() {
          $(this).attr('disabled', 'disabled');
          // It also helps to let the user know what's going on:
          $(this).val('Processing...');
          // Handle event here 
          $(this).removeAttr('disabled');
      })
      

      I don't think this works on links though.

提交回复
热议问题