我有一個jQuery對話框出現並加載一個外部頁面。在該頁面中,我運行了一個setInterval()
函數,它每隔1秒連續查詢我的服務器(AJAX)。問題是,當我關閉對話框時,setInterval不會停止運行。jQuery對話框中的javascript setInterval()不會停止銷燬或刪除
這裏是對話框代碼:
var theUrl = 'someUrl';
var popUp = document.createElement('div');
$(popUp).dialog({
width: 400,
height: 270,
title: "Some Title",
autoOpen: true,
resizable:false,
close: function(ev, ui) {
$(this).dialog('destroy');
},
modal: true,
open: function() {
$(this).load(theUrl);
}
});
想拜訪密切$(this).dialog('destroy')
和$(this).remove()
和document.body.removeChild(popUp)
。沒有工作。反正有'卸載'加載頁面?
setInterval與DOM或jQuery無關。它需要單獨清除,可能是由於像「close」這樣的DOM事件。 – Bergi