jQuery click event handler is called twice for a checkbox

前端 未结 10 1963
野趣味
野趣味 2020-12-09 17:08

I have a problem with the following code in an ASPX page:



        
10条回答
  •  星月不相逢
    2020-12-09 17:34

    I have just experienced the same thing, but am not sure that event bubbling is causing my issue. I have a custom tree control, and when an item is opened, I use $(id).click() to attach a handler to all elements of a certain kind.

    I suspect that this means that existing items elsewhere that already have the event, may then have it added again. I found that unbinding everything then re-binding solved my problem, thus:

    $('img.load_expand').unbind("click").click(function()
    {
      // handler
    });
    

提交回复
热议问题