Using .one() with .live() jQuery

前端 未结 6 2029
感动是毒
感动是毒 2020-12-09 04:32

I was using the live() function:

$(\'a.remove_item\').live(\'click\',function(e) {});

I needed to change this to one()

6条回答
  •  感情败类
    2020-12-09 04:51

    Try this:

    $('a.remove_item').live('click',function(e) {
      if($(e.target).data('oneclicked')!='yes')
      {
        //Your code
      }
      $(e.target).data('oneclicked','yes');
    });
    

    This executes your code, but it also sets a flag 'oneclicked' as yes, so that it will not activate again. Basically just sets a setting to stop it from activating once it's been clicked once.

提交回复
热议问题