【问题标题】:load content from already loaded content从已加载的内容加载内容
【发布时间】:2019-11-27 03:34:27
【问题描述】:

我有一个菜单,我可以从中将不同 html 页面中的内容加载到我的 div id="content";我想从加载的内容中加载内容;不工作

我尝试了所有类型的东西,但完全迷失了,比如 .live(click,..) 和 empty()、remove() 等等。 我一次又一次得到的是相当的内容,但不在我的 div 中,即没有 css,加上点击加载内容中的链接会将我带到另一个页面,而不是将该页面中的内容加载到我当前的页面中。

$(document).ready(function() {


    $('#nav li a').click(function(){

        var toLoad = $(this).attr('href')+' #content';

        $('#content').hide('fast',loadContent);

        function loadContent() {
            $('#content').load(toLoad,'',showNewContent())
        }

        function showNewContent() {
            $('#content').show('normal');
        }

        return false;    
    });
});

【问题讨论】:

    标签: jquery load innerhtml


    【解决方案1】:

    我现在明白了:问题是事件委托,意思是:加载的内容没有被 dom 结构注册。所以你必须将点击事件委托给祖先, 最初加载的:

    /* 点击时 - 事件委托给#staticAncestor / / $(staticAncestors).on(eventName, dynamicChild, function() {}); */

    这是一种本地解决方案;我不再找到它,但也有全球答案 研究“事件委托”

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-08-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-07
      • 1970-01-01
      相关资源
      最近更新 更多