2014-04-30 13 views
0

我想在第二秒自动刷新div部分。我希望每x秒div div应该显示不同的内容,并且在显示最后的内容之后,它应该显示从开始的内容如何在x间隔自动刷新div部分?

我该怎么做到这一点?

<script type="text/javascript" 
    src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script> 
<script type="text/javascript"> 
    var auto_refresh = setInterval(
     function() { 
      $('#push').load('F3.jsp').fadeIn("slow"); 
     }, 10000); // refresh every 10000 milliseconds 
</script> 
<div class="push"> 
    <table width="100%" border="1" align="center" 
      cellpadding="0" cellspacing="1" bordercolor='66A8FF'> 
     <% 
      int i=5; 
      int j=6; 
      int k=7; 
     %> 
     <tr bgcolor="0F57FF" style="border-collapse:collapse"> 
      <td width="50%" height="50px" align="center" style="font-size:24px"> 
       <font color="#fff"><%= i%></font> 
      </td> 
     </tr> 
    </table> 
</div> 

我想说明的i,j,k值周期性为表中的每x秒。

+0

http://stackoverflow.com/questions/1224463/is-there-any-way-to-call-a-function-periodically-in-javascript 这个链接可以帮助你。 – Valath

+0

你需要为你的'tr'和'table'使用结束标签。 – Cerbrus

+0

您不需要jsp也不需要重新加载,只需更改单元格中的数字即可。你真的想这么做吗?还是在'F3.jsp'中有其他事情? –

回答

0

此代码可能会对您有所帮助。

$('.push').html(''); 
var x= 1000; 
var countRefresh = 0; 
var contentCount; 
counter=setInterval(refreshFun, x); 


function refreshFun() 
{ 
    if(countRefresh == contentCount){ 
     clearInterval(counter); 
     counter=setInterval(refreshFun, x); 
    }else{ 
     var i=5; 
     var j=6; 
     var k=7; 
     var table = "{Your table html}"; 

     $('.push').html(table); 
     countRefresh++; 
    } 

} 

谢谢。