jquery load div after page load

岁酱吖の 提交于 2019-11-29 15:47:24

问题


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.

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>

回答1:


$(document).ready(function(){

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

});



回答2:


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
});



回答3:


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

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




回答4:


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 ;)



来源:https://stackoverflow.com/questions/5301916/jquery-load-div-after-page-load

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!