jquery.one()

one() 方法为被选元素附加一个或多个事件处理程序,并规定当事件发生时运行的函数。

当使用 one() 方法时,每个元素只能运行一次事件处理器函数。

也就是,绑定的function,只会执行一次。

var testBt=$('<button id="testBtClick" style="position:absolute;top:10px;left:210px;z-index:999;">click2</button>');

    $('body').append(testBt);

    testBt.one('click',function(){

        // location.reload(true);

        // location.replace(location.href);

        alert('只执行一次')

    });

参考:

http://www.w3school.com.cn/jquery/event_one.asp

原文地址:https://www.cnblogs.com/simonbaker/p/4443569.html