Home > Web Front-end > JS Tutorial > Registering events multiple times will cause an event to be triggered multiple times_javascript tips

Registering events multiple times will cause an event to be triggered multiple times_javascript tips

WBOY
Release: 2016-05-16 17:25:55
Original
1492 people have browsed it

A JavaScript logic will automatically bind the function to the click event of the button, but this code will register the event repeatedly. This relies on the onNext function to be triggered multiple times when the button is clicked.

This is because JQuery does not internally determine whether to bind multiple times. It is suspected that it uses an array internally to save the event function, and does not remove duplicates.

The following code prevents this problem. The solution is simple.

Copy code The code is as follows:

if (!this.hasPageBarEvents) {
$ (".pNext").on("click", this, this.onNext);
this.hasPageBarEvents = true;
}

Be careful about this feature when using JQuery in the future .
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template