0

我对动态加载内容有疑问。我有一个菜单,在 div 点击后隐藏,他们正在加载新内容并且他正在移动..它工作正常,但是在新内容中我有子菜单,它想对菜单使用相同的效果,但是是出现问题和链接导致立即通过

也许它更容易理解:):我有CONTNET DIV,这是动态加载如果我点击菜单中的链接......新内容正在正确加载。在新内容中,我有子菜单,但如果我点击链接,所有网站都会重新加载......如果我只想加载“内容 div”,我能做什么..

代码有什么问题?

 $(document).ready(function() {

    var hash = window.location.hash.substr(1);
    var href = $('.nav li a').each(function(){
        var href = $(this).attr('href');
        if(hash==href.substr(0,href.length-5)){
            var toLoad = hash+'.html #content';
            $('#content').load(toLoad)
        }                                           
    });

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

        var toLoad = $(this).attr('href')+' #content';
        $('#content').hide('fast',loadContent);
        $('#load').remove();
        $('#wrapper').append('<span id="load">LOADING...</span>');
        $('#load').fadeIn('normal');
        window.location.hash = $(this).attr('href').substr(0,$(this).attr('href').length-5);
        function loadContent() {
            $('#content').load(toLoad,'',showNewContent())
        }
        function showNewContent() {
            $('#content').show('normal',hideLoader());
        }
        function hideLoader() {
            $('#load').fadeOut('normal');
        }
        return false;

    });

});

我尝试使用您的建议,但它没有效果..

我做了示例页面..

http://zaciszepuck.pl/site/

您可以看到,如果您单击菜单,一切正常,但是如果您要单击“欢迎内容”中的子菜单,则所有站点都会重新加载,但是如果再次单击,则只会加载 Content Div..

有人有想法吗?

4

2 回答 2

0

什么是你的母语?我认为它会更容易回答。

这样对吗?您在主菜单中单击任何项​​目并使用 AJAX 加载到页面新菜单,但新菜单中的项目不调用 AJAX 请求?

如果是这样,您需要根据需要将 AJAX 函数调用应用于新菜单、其项目或孔加载的内容。

$(".nav li a").click(function funcName() {
    ...
    $("#content").load(toLoad, function (){
        showNewContent();
        $(".nav li a").click(funcName);/*or other submenu selector*/
    });
    ...
});

我认为您的代码太复杂了,需要一些改进。

于 2011-01-24T00:26:53.603 回答
0

根据我对您的查询的理解,这可能会做到。

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

        var toLoad = $(this).attr('href')+' #content';
        $('#content').hide('fast',loadContent);
        $('#load').remove();
        $('#wrapper').append('<span id="load">LOADING...</span>');
        $('#load').fadeIn('normal');
        window.location.hash = $(this).attr('href').substr(0,$(this).attr('href').length-5);
        function loadContent() {
            $('#content').load(toLoad,'',showNewContent())
        }
        function showNewContent() {
            $('#content').show('normal',hideLoader());
        }
        function hideLoader() {
            $('#load').fadeOut('normal');
        }
        return false;

    });
于 2011-01-24T00:37:15.737 回答