JS页面加载完成时执行某个操作

23-08-12 14:12 字数 1066 阅读 972
jQuery.fn.wait = function (func, times, interval) {
    var _times = times || 100, //100次
        _interval = interval || 20, //20毫秒每次
        _self = this,
        _selector = this.selector, //选择器
        _iIntervalID; //定时器id
    if (this.length) { //如果已经获取到了,就直接执行函数
        func && func.call(this);
    } else {
        _iIntervalID = setInterval(function () {
            if (!_times) { //是0就退出
                clearInterval(_iIntervalID);
            }
            _times <= 0 || _times--; //如果是正数就 --
            _self = $(_selector); //再次选择
            if (_self.length) { //判断是否取到
                func && func.call(_self);
                clearInterval(_iIntervalID);
            }
        }, _interval);
    }
    return this;
}


var mergeBtns = $("[class^=merge-request-container]").find("[class^=content-container__]").find("[class^=main__]").find(
    "[class^=show__]").find("[class^=container__]");
mergeBtns.wait(function () {
    console.log("mergeBtns", mergeBtns);
    // $(mergeBtns)[2].find("[class^=merges__]").remove();
});
0人点赞>
关注 收藏 改进 举报
0 条评论
排序方式 时间 投票
快来抢占一楼吧
请登录后发表评论