Only fire an event once?

前端 未结 7 1858
谎友^
谎友^ 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 07:02

    Additionally, you can do this:

    window.addEventListener("click", function handleClick(e) {
        window.removeEventListener("click", handleClick);
    
        // ...
    });
    
    0 讨论(0)
提交回复
热议问题