Only fire an event once?

前端 未结 7 1876
谎友^
谎友^ 2020-11-27 06:06

How do I control only firing an event once?

Actually, a quick google appears to allude to the fact that .one helps..

7条回答
  •  清歌不尽
    2020-11-27 06:39

    You can use jQuery's one method, which will subscribe to only the first occurrence of an event.
    For example:

    $('something').one('click', function(e) {
        alert('You will only see this once.');
    });
    

提交回复
热议问题