jQuery jheartbeat-要停止进程

时间:2018-11-26 21:53:40

标签: jquery function

使用以下JS脚本。 效果很好,但是我希望能够停止该过程,并且无法弄清楚该如何实现。

$.jheartbeat = {
options: {
    url: "heartbeat_default.asp",
    delay: 10000
},
beatfunction:  function(){},
timeoutobj:  {
    id: -1
},
set: function(options, onbeatfunction) {
    if (this.timeoutobj.id > -1) {
        clearTimeout(this.timeoutobj);
    }
    if (options) {
        $.extend(this.options, options);
    }
    if (onbeatfunction) {
        this.beatfunction = onbeatfunction;
    }

    this.timeoutobj.id = setTimeout("$.jheartbeat.beat();", this.options.delay);
},

beat: function() {
    $("#HeartBeatDIV").load(this.options.url);
    this.timeoutobj.id = setTimeout("$.jheartbeat.beat();", this.options.delay);
    this.beatfunction();
}

};

希望能够添加一个功能来终止心跳或停止调用后端页面的进程。

1 个答案:

答案 0 :(得分:0)

this.timeoutobj.id是超时被分配给的变量,但是您尝试清除clearTimeout(this.timeoutobj);。您定位错误的变量。

清除应该为clearTimeout(this.timeoutobj.id),这将与您在kill方法中执行的操作相同。