jQuery动态加载内容

发布于 2024-10-14 00:40:34 字数 1585 浏览 5 评论 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 ..

有人有想法吗?

I have a problem with dynamic loading contents. I have the menu where after div clicking is hiding, they are loading new contents and he is moving.. it works correctly, however in new contents I have submenu, which would like to use the same effect for what for the menu, however is coming into existence the problem and the link cause the immediate passage

Maybe it's more understandable:) : I have CONTNET DIV, which is dynamic loading If I click link in MENU... The new content is loading correctly. In new content I have submenu but if I click links there all site is reloaded... What I can do if I want loading only 'content div'..

What's is wrong in code ?

 $(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;

    });

});

I tried to use your advice , but it doesn't effect..

I did example page..

http://zaciszepuck.pl/site/

You can see, if you click on menu, all it's ok, but if you are going to click submenu in 'welcome content' all site are reloaded, but if you click again, only Content Div is loaded..

anybody has an idea ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

过气美图社 2024-10-21 00:40:34

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

$('.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;

    });

From what I could understand of your query, this might do it.

$('.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;

    });
疏忽 2024-10-21 00:40:34

您的母语是什么?我认为在其中回答会更容易。

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

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

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

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

What is your native language? I think it would be easier to answer in it.

Is it right? You click in main menu any item and load to the page new menu using AJAX, but items in new menu doesn't call AJAX request?

If it is so, you need to apply the AJAX function call to the new menu, its items or the hole loaded content, as you like.

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

I think your code is too complicated at all, it needs some improvements.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文