prevent multiple binding of click events with JQuery

sometimes we will code like this to add a click event listener in js:

1
$('selector').click(function(){do something...});

However,when this code is executed multiple times,the click event listener will be add repeatedly.
so,the method to prevent it is unbind it before add this click event.

1
$('selector').off('click').on('click', function () {do something...});


转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论,也可以邮件至 jaytp@qq.com

文章标题:prevent multiple binding of click events with JQuery

本文作者:子非鱼

发布时间:2019-05-07, 14:28:45

最后更新:2019-05-07, 14:37:58

原始链接:https://Wangsr.cn/2019/05/07/prevent-multiple-binding-of-click-events-in-js/

版权声明: "署名-非商用-相同方式共享 4.0" 转载请保留原文链接及作者。

目录
×

喜欢就点赞,疼爱就打赏