How to prevent events from being bound multiple times

后端 未结 5 1384
后悔当初
后悔当初 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:59

    Simplest solution from here bind event only once

    Copied code sample:

    function someMethod()
    {
        $(obj).off('click').on('click', function(e) {
            // put your logic in here 
        });
    }
    

提交回复
热议问题