Javascript 间隔并不总是被清除

Javascript 间隔并不总是被清除,javascript,jquery,html,twitter-bootstrap,Javascript,Jquery,Html,Twitter Bootstrap,我花了很多时间清理一个非常简单的间隔。有时有效,有时无效 我在第一次启动引导模式时通过以下方式设置间隔: $('#myModal').on('shown.bs.modal', function (e) { getParticipants(); getParticipantsInt = setInterval(getParticipants, 15000); }); 然后,我尝试在用户确认(通过另一个模式)要删除用户时清除间隔: $("#deleteBt

我花了很多时间清理一个非常简单的间隔。有时有效,有时无效

我在第一次启动引导模式时通过以下方式设置间隔:

$('#myModal').on('shown.bs.modal', function (e) {
        getParticipants();

        getParticipantsInt = setInterval(getParticipants, 15000);
    });
然后,我尝试在用户确认(通过另一个模式)要删除用户时清除间隔:

$("#deleteBtn").click(function() {
            clearInterval( getParticipantsInt );  
            $(parent).closest('tr').remove(); // Remove the row
            test.dropUser(userId)
            .success(function(response){

                    $('#hangupPartModal').modal('hide');
                    setTimeout( function()
                    { 
                        getParticipantsInt = setInterval(getMtgParticipants, 15000);
                    }, 5000);
            });

        });
我想要的行为是,一旦显示了模态,就调用该方法,然后设置一个间隔,每15秒调用一次该方法

当我们删除一个用户时,取消这个间隔,然后再等20秒重新启动它

问题是,有时在20秒结束之前它仍然被调用。此外,在删除用户之前,有时我可以一行看到getParticipants()方法2到3次

我错过了什么?设置/清除间隔应容易

$('#myModal').on('shown.bs.modal', function (e) {
        getParticipants();
        clearInterval(getParticipantsint);

        getParticipantsInt = setInterval(getParticipants, 15000);
    });

我假设getParticipantsInt是一个全球性的。如果这是真的,那么问题很可能是您有多个时间间隔,并且只清除其中一个时间间隔。

不确定这是否与问题有关,但您的两个不同时间间隔调用不同的函数,
getmtgpparticipants
vs
getParticipants
。所以你不是在“重新启动”它,而是在开始新的东西;错别字。好的,是的。看起来我已经运行了多个时间间隔,但是使用这段代码并不能解决问题。不确定是什么原因造成的。我还有其他问题。当我清理代码时,你的方法最终奏效了。