jQuery: Single button click, click event firing two or more times

前端 未结 8 1603
被撕碎了的回忆
被撕碎了的回忆 2021-01-30 13:45

I have HTML input and button elements. I use the buttons to submit forms, open secondary windows, etc. The problem is, a single click is turning into 2 (and sometimes many more

8条回答
  •  太阳男子
    2021-01-30 14:46

    for me it was caused by

    $(function() {
        $('.some-element').click(function() {
            //event that fires twice
        });
    
        //some exception-throwing code here
    });
    

    jQuery was calling the anonymous ready function twice(?!) because of the exception so the click function would be bound twice.

提交回复
热议问题