我有很多代码,并希望避免将其全部发布在这里,但如果我需要,我会或者我会模拟类似的东西。
我的问题是,我有一个隐藏的 div,我正在将页面加载到(使用 load())然后取消隐藏(使用 fadeIn())。当需要将这个 div 移开时,我将一个空页面加载到 div 中,然后将其淡出。我已经通过将 javascript 警报放入其中来测试空页面,它确实正在加载,但我在第一页中加载到 div 中的 Javascript 仍在运行。这个 Javascript 现在是否属于父页面?有没有办法卸载它,使其不再运行或可用?稍后我需要使用不同的动态内容再次加载页面,并且仍在运行的 Javascript 与再次加载时相同的 Javascript 发生冲突。然后再次。
我希望这个描述是可以理解的。我猜我的问题可能很简单,并且与我尚未理解的层次结构有关。
谢谢!
- - - - - - - 编辑
这是加载页面中的Javascript。它引用的所有类和 id 都存在于加载的页面中。(代码改编自http://www.ilovecolors.com.ar/编码的标签行为)
//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);
});