问题描述
这是我的html code:
this is my html code:
<body onload="fun1()">
<ul id="nav" class="nav" style="font-size:12px;">
<li><a href="#" id="m_blink" onclick="fun1()">Tab1</a></li>
<li><a href="#" id="d_blink" onclick="fun2()">Tab2</a></li>
<li><a href="#" id="k_blink" onclick="fun3()">Tab3</a></li>
</ul>
</body>
<div id='home'></div>
该脚本加载在一个'家'DIV网页内容,如果我点击tab1的特定tab1.php装在家的div,当我点击TAB2特别tab2.php是装在家的div,当我点击TAB3特别tab3.php加载在家里DIV,
this the script loading the page content in a 'home' div , and if i click 'tab1' that particular 'tab1.php' loading in 'home' div and when i click 'tab2' particular tab2.php is loading in 'home' div and when i click tab3 particular tab3.php is loading in home div,
<script>
function fun1(){
$("#home").load("tab1.php",{},function(){});
}
function fun2(){
$("#home").load("tab2.php",{},function(){});
}
function fun3(){
$("#home").load("tab3.php",{},function(){});
}
</script>
当我点击TAB1页面加载在家里股利和这个家div有当TAB2页面家庭DIV装载刷新每5秒,这家div有刷新5秒一样TAB3
when i click on the tab1 page is loaded in home div and this home div has to refresh for every 5 seconds when tab2 page is loaded in home div and this home div has to refresh for 5 seconds and same as tab3
请检查的onload功能对身体标记!
please check the 'onload' function is for body tag!
和我尝试使用的setInterval(函数(){});像这样的:
and i tried using setInterval(function() {}); like this :
function fun1(){
setInterval(function(){
$("#home").load("tab1.php",{},function(){});
},5000);
}
function fun2(){
setInterval(function(){
$("#home").load("tab2.php",{},function(){});
},5000);
}
function fun3(){
setInterval(function(){
$("#home").load("tab3.php",{},function(){});
},5000);
}
和问题是,当我通过AJAX load()函数比加载页面的整个身体被称为网页,所以我不希望加载整个页面,我想刷新特定的div家div的页面只,请建议如何解决这个问题。
And the problem is when i called the page through ajax load() function than whole body of the page is loading, so i dont want to load whole page i want to refresh the page of particular div home div only, please suggest how to solve this problem.
请检查的onload()函数,我已经使用调用默认的页面tab1.php
please check onload() function i have used to call the default page tab1.php
推荐答案
我建议你使用jQuery的的.data()
方法来提供所需的额外的信息:
I suggest you to use .data()
method of jQuery to provide required extra info:
<ul id="nav" class="nav" style="font-size:12px;">
<li><a href="#" data-url="tab1.php">Tab1</a></li>
<li><a href="#" data-url="tab2.php">Tab2</a></li>
<li><a href="#" data-url="tab3.php">Tab3</a></li>
</ul>
由于您使用jQuery的话,最好使用编写脚本像这样不显眼的方式:
As you are using jQuery then better to use unobtrusive way of writing scripts like this:
$('#nav a').on('click', function(e){
e.preventDefault();
$('.active').removeClass('active'); // removes the active class from other link
$(this).addClass('active'); // adds the active class to current cliked link
setInterval(function(){
$("#home").load($('.active').data('url'),{},function(){}); // populates the div with data-url of active class.
}, 5000);
});
$('#nav li:eq(0) a').trigger('click'); // triggers the first link's click.
这篇关于如何刷新特定分区的内容时,页面加载通过AJAX load()函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!