JQuery - 使用 load() 将页面加载到 div - 如何卸载?

标签 jquery load jquery-load

我有很多代码,希望避免将其全部发布在这里,但如果我需要的话,我会或者我会模拟类似的东西。

我的问题是,我有一个隐藏的 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);
});

最佳答案

javascript每次都是相同的,只有加载页面的内容发生变化(我假设内容发生变化,否则每次都重新加载是没有意义的);因此,我会将脚本放在 div 中加载的文件之外,并在主页中仅加载一次。

关于JQuery - 使用 load() 将页面加载到 div - 如何卸载?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9030576/

相关文章:

javascript - Jquery load() 和 colorbox() 在一起

java - jquery 与 spring mvc 在 java 中

Javascript 检索字符后的哈希值

jquery - 外部数据加载到数据网格后在 Angular 中注册 ng-click

jquery - 使用jquery将标签类添加到另一个标签

jquery - 直到过度效果完成后链接才有效

ruby - 第二次如何require

javascript - 如何在 Javascript 中将变量从一个文件发送到另一个文件?

java - 图标图像加载速度不够快

file - Java JAR 找不到文件