我有很多的代码,并希望避免在这里发布,但如果我需要我会或我会嘲笑类似的东西。JQuery - 使用load()加载页面到div中 - 如何卸载?
我的问题是,我有一个隐藏的div,我正在加载一个页面(加载()),然后取消隐藏(与fadeIn())。当需要将这个div放开时,我会将一个空白页面加载到div中,然后淡出它。我已经通过向其中添加一个JavaScript警报来测试空白页面,并且确实正在加载,但是我加载到第一页中div的Javascript仍在运行。此Javascript现在是否属于父页面?有没有办法卸载它,使它不再运行或可用?我需要稍后再使用不同的动态内容加载页面,而仍在运行的JavaScript与再次加载时使用相同的Javascript冲突。然后再次。
我希望这个描述是可以理解的。我猜测我的问题可能非常简单,并且与我尚未理解的病友有关。
谢谢!
-------------编辑
这里是加载的页面中的Javascript。它所引用的所有类和标识都存在于加载的页面中。
//array to store IDs of our tabs
var tabs = [];
//index for array
var ind = 0;
//store setInterval reference
var inter = 0;
//change tab and highlight current tab title
function change(stringref){
//hide the other tabs
jQuery('.tab:not(#' + stringref + ')').hide();
//show proper tab, catch IE6 bug
if (jQuery.browser.msie && jQuery.browser.version.substr(0,3) == "6.0")
jQuery('.tab#' + stringref).show();
else
jQuery('.tab#' + stringref).fadeIn(200);
//clear highlight from previous tab title
jQuery('.htabs a:not(#' + stringref + 't)').removeClass('select');
//highlight currenttab title
jQuery('.htabs a[href=#' + stringref + ']').addClass('select');
}
function next(){
alert("change");
//call change to display next tab
change(tabs[ind++]);
//if it's the last tab, clear the index
if(ind >= tabs.length)
ind = 0;
}
jQuery(document).ready(function(){
//store all tabs in array
jQuery(".tab").map(function(){
tabs[ind++] = jQuery(this).attr("id");
})
//set index to next element to fade
ind = 1;
//initialize tabs, display the current tab
jQuery(".tab:not(:first)").hide();
jQuery(".tab:first").show();
//highlight the current tab title
jQuery('#' + tabs[0] + 't').addClass('select');
//handler for clicking on tabs
jQuery(".htabs a").click(function(){
//if tab is clicked, stop rotating
clearInterval(inter);
//store reference to clicked tab
stringref = jQuery(this).attr("href").split('#')[1];
//display referenced tab
change(stringref);
return false;
});
//start rotating tabs
inter = setInterval("next()", 3500);
});
div中的JavaScript是否包含事件等外部元素?你能提供的JavaScript? – 2012-01-27 08:21:25
我已将Javascript加入到我上面的描述中。 – Imaginary 2012-01-27 08:27:55