jQuery click event handler is called twice for a checkbox

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

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



        
10条回答
  •  情书的邮戳
    2020-12-09 17:26

    I ran into the same issue with a click event, and found this article. In essence, if you have more than one jQuery document-ready functions inside the tags, you can get multiple events. The fix is, of course, to not do that, or to unbind the click event and rebind it, as noted above. Sometimes, with multiple javascript libraries, it can be hard to avoid multiple document.ready()'s, so the unbind is a good workaround.

    
    $('#my-div-id').unbind("click").click(function()
      {
        alert('only click once!');
      }
    
    

提交回复
热议问题