【发布时间】:2011-10-15 17:08:36
【问题描述】:
大家好,我正在做一个项目,我使用 jQuery 将页面加载到 div 中,每个页面都有自己的 jQuery 脚本,我的问题是之前加载的脚本没有从 DOM 中清除,这会产生更大的问题我的项目。
例如,我在一个页面中有一组计时器,它会自动保存数据,但是当我更改页面时,计时器仍在运行并弄乱了内容。
我像这样管理不断变化的页面:
$(document).ready(function() {
$('li').click(function (event) {
$('.progressbarone').hide();
var theitem = this.id;
//isf ajax to load with addon
var thefile = "isf_ajax.php?addon="+this.id;
var progress = '<span class="progressbarone"><img src="'
+ THEMEURL
+ '/gfx/images/progessbar1.gif" width="20" height="16" /></span>';
// pre actions
$('.'+ theitem +'_item')
.append(progress)
.children(':last')
.hide()
.fadeIn(1000);
$('li').removeClass('active');
$(this).addClass('active');
// load the page
$('#childpage').remove();
$('#officetable').html('<div id="childpage">loading</div>');
$('#childpage').load(thefile, function() {
// after load actions
$('.progressbarone').fadeOut(2000);
});
});
});
如您所见,我有两个 div,一个称为 office table,用于处理子页面,而子页面包含更改页面的内容。但是如您所见,我使用了 remove();功能也一样,之后我将子页面放置到 officetable 并发布了文件的内容,但它仍然没有删除我之前加载的脚本。
谢谢你们。
【问题讨论】: