jQuery click events firing multiple times

后端 未结 25 2196
不知归路
不知归路 2020-11-22 11:01

I\'m attempting to write a video poker game in Javascript as a way of getting the basics of it down, and I\'ve run into a problem where the jQuery click event handlers are f

25条回答
  •  隐瞒了意图╮
    2020-11-22 11:52

    In my case I was using 'delegate', so none of these solutions worked. I believe it was the button appearing multiple times via ajax calls that was causing the multiple click issue. The solutions was using a timeout so only the last click is recognized:

    var t;
    $('body').delegate( '.mybutton', 'click', function(){
        // clear the timeout
        clearTimeout(t);
        // Delay the actionable script by 500ms
        t = setTimeout( function(){
            // do something here
        },500)
    })
    

提交回复
热议问题