How to prevent events from being bound multiple times

后端 未结 5 1362
后悔当初
后悔当初 2021-01-01 15:10
 $(\'.ajax\').click
 (        
    function()
    {
        // If been bound then we need to return here.
        alert(\':D\');
    }
 )

 $(\'.ajax\').click
 (
            


        
5条回答
  •  离开以前
    2021-01-01 15:41

    try unbinding it before binding:

    $(".ajax").unbind("click").click( 
          function () { 
        alert("Hello"); 
      } );
    

    read this for some more information.

提交回复
热议问题