jQuery click events firing multiple times

后端 未结 25 2862
不知归路
不知归路 2020-11-22 11:01

I\'m attempting to write a video poker game in Javascript as a way of getting the basics of it down, and I\'ve run into a problem where the jQuery click event handlers are f

25条回答
  •  面向向阳花
    2020-11-22 11:43

    We must to stopPropagation() In order to avoid Clicks triggers event too many times.

    $(this).find('#cameraImageView').on('click', function(evt) {
       evt.stopPropagation();
       console.log("Camera click event.");
    });
    

    It Prevents the event from bubbling up the DOM tree, preventing any parent handlers from being notified of the event. This method does not accept any arguments.

    We can use event.isPropagationStopped() to determine if this method was ever called (on that event object).

    This method works for custom events triggered with trigger(), as well.Note that this will not prevent other handlers on the same element from running.

提交回复
热议问题