jQuery 页面加载后jquery加载div

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5301916/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 18:56:11  来源:igfitidea点击:

jquery load div after page load

jqueryhtmlload

提问by Ravi

Actually what I am looking for loading is loading the page first and then a div with lots of data. So, I want to load the main page first and then body div content using jQuery function with some delay.

实际上,我正在寻找加载的是先加载页面,然后加载包含大量数据的 div。所以,我想先加载主页,然后使用 jQuery 函数加载主体 div 内容,但有一些延迟。

What is the simple way of implementing this..?

实现这个的简单方法是什么..?

 <div id="container">
      <div id="header">navigation</div>
      <div id="body" class="body">Body</div>
      <div id="footer">footer</div>
 </div>

回答by FatherStorm

$(document).ready(function(){

  $.get('ajax/page.php', function(data) {
    $('#body').html(data);
  });

});

回答by ankimal

The shorthand version:

速记版:

$(function(){
 $("#body").html();
 //...
});

If you want to do it after an interval

如果你想在间隔后做

function load(){
 $("div").html(...);
}
$(function(){
  // Interval of 5 secs.
  setInterval("load()",5000);
  //http://www.w3schools.com/jsref/met_win_setinterval.asp
});

回答by Kaszoni Ferencz

This is what I've done:

这就是我所做的:

function newContent()
{
    $("#navix").load("new1.php");
}
$(function(){
  // Interval of 5 secs.
  setInterval("newContent()",5000);
  //http://www.w3schools.com/jsref/met_win_setinterval.asp
});

It works great ;)

它工作得很好;)

回答by Jan Zyka

$(document).ready(function() {
  // Handler for .ready() called.
});

The ready function is called when page is fully loaded. You can load your div in it.

当页面完全加载时调用 ready 函数。您可以在其中加载您的 div。