如何提供具体的ID给setInterval()
,然后通过ID调用clearInterval()
。提供setInterval的ID并通过ID清除
$('.notify').each(function() {
var chkr = $(this).find('span').text();
if (chkr == 'Offline') {
if (typeof(clearC) !== 'undefined') {
clearInterval(clearC);
}
// how can i provide the ID of "clearC" below
clearC = setInterval(function() {
soundOn();
}, 500);
}
else {
//how can i clear "clearC" with the ID provided in if statement
if (typeof(clearC) !== 'undefined') {
clearInterval(clearC);
}
}
});
问题是当if
声明执行然后声音继续。但对于下一行,它输入else
声明(因为“在线”)并清除间隔,尽管它不应该。
所以我的问题是清除clearInterval
为特定的行,直到找到“在线”文本。
什么不工作? (设置/清除间隔中没有ID) – Amit