小编ank*_*kit的帖子

如何停止执行JavaScript间隔功能?

我在setIntervel()中有一个函数,我想明确地停止执行这个函数.我怎么能这样做???函数是..

function autoLoad(chatboxtitle, msgId) {
    setInterval(function() {
        if (msgId != '') {
            $.ajax({
                type: "POST",
                url: "../WebService1.asmx/GetMessagesDetail",
                data: '{ "messageID": "' + msgId + '" }',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                async: true,
                cache: false,
                success: function(msg) {
                    $("#chatbox_" + chatboxtitle + ".chatboxcontent").empty();
                    $("#chatbox_" + chatboxtitle + ".chatboxcontent").append(msg.d);
                    $contentLoadTriggered = false;
                },
                error: function(x, e) {
                    alert("error");
                }
            });
        }
    }, 8000);
}
Run Code Online (Sandbox Code Playgroud)

javascript jquery setinterval

1
推荐指数
1
解决办法
1525
查看次数

标签 统计

javascript ×1

jquery ×1

setinterval ×1