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

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

    I had a problem with modal dialog windows. The event fired once for each time I had opened a dialog in the session. No problem on the first window, fired twice on the second window, fired three times on the third window, etc.

    I found that the initialization function for the dialog was being called each time I opened a new dialog window in the same session. I added a global variable notInit = -1 and assigned the value to 1 when running init. I checked the value of notInit before running the init function and only proceeded with init if the value was -1.

提交回复
热议问题