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

前端 未结 8 1690
被撕碎了的回忆
被撕碎了的回忆 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:35

    Your problem may be happening because you are assigning the same handler to the click event multiple times. I suggest you check that the line where you assign the handler is not being called multiple times inadvertently. Another solution could be a call to unbind (deprecated 3.0) or off (superseeded) first:

    $("#myButton").unbind("click").click(myHandler); // deprecated
    $("#myButton").off("click").click(myHandler); // superseeded
    

    But without seeing some code I'm just guessing.

提交回复
热议问题