jQuery bind firing multiple times?

后端 未结 2 1701
一个人的身影
一个人的身影 2021-01-05 15:10
$(\".container\").on(\"contextmenu\", \".photos-bottom .albums li\", function(e) {

$(\'html\').bind(\'click\', function (event) {
    alert(id);
});

return false;
         


        
相关标签:
2条回答
  • 2021-01-05 15:30

    Because your click event is being bound every time a context menu event occurs, you're actually adding an additional bind each time you right click. This is the reason for the ever-growing number of event executions.

    You should either:

    a) unbind the event when the context menu is closed, or

    b) bind the click event outside of your contextmenu callback function.

    0 讨论(0)
  • 2021-01-05 15:36

    $('html').unbind('click').bind('click') fixed it.

    0 讨论(0)
提交回复
热议问题