jQuery click events firing multiple times

后端 未结 25 2834
不知归路
不知归路 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:46

    .one only fires once for the lifetime of the page

    So in case you want to do validation, this is not the right solution, because when you do not leave the page after validation, you never come back. Better to use

    $(".bet").on('click',function() 
    { //validation 
       if (validated) { 
          $(".bet").off('click'); //prevent to fire again when we are not yet off the page
          //go somewhere
        }
    });
    

提交回复
热议问题