简体   繁体   English

jQuery .load和html问题

[英]JQuery .load and html issue

I am trying to use Javascript to load different pages when you press a link. 当您按链接时,我试图使用Javascript加载不同的页面。 Here is the function I am using to change the page. 这是我用来更改页面的功能。

function loadPage(url){
    $(".body").fadeOut(400, function(){
        $(".body").load(url, function(){
            $(".body").fadeIn(400);
        });
    });
};

The problem is, it fades the stuff into the page, but it disappears once the fadeIn is done. 问题是,它会将内容淡入页面,但是一旦完成fadeIn,它就会消失。 The code html from the file is still in the main files html, it just doesn't show up. 该文件中的代码html仍在主文件html中,只是没有显示。

I had an issue, and I used this. 我有一个问题,我用了这个。 File in your case would be the url: 在您的情况下,文件将是url:

var loader = function(file) {

   $('.body').fadeOut(500);

 $.ajax({ 
     url: file

     success: function(data) {

        $('.body').html(data);

$('.body').fadeIn(500);

  }

 });


  }

Changed the code to try and match what your looking to do, tested it with just a div with a background and it seems to work okay. 更改了代码以尝试与您的工作相匹配,仅在具有背景的div上对其进行了测试,并且看起来工作正常。

Is this the same as what you have ? 这和你拥有的一样吗?

Andrew 安德鲁

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM