bind event only once

前端 未结 13 2258
予麋鹿
予麋鹿 2020-12-05 03:45

I have the following code:

function someMethod()
{
  $(obj).click(function {});
}

someMethod is called twice and thus click event is binded

13条回答
  •  情歌与酒
    2020-12-05 04:15

    Or use jQuery's one() function which is similar to on() but only fires the event once, even if you bind it multiple times.

    http://api.jquery.com/one/

提交回复
热议问题