0

例子

 <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 () {
    $('#div').load('another.page');
}, 1000);
    </script>

我不想加载'another.page' 我只想刷新'#div' div 是否有可能

谢谢你

4

3 回答 3

2

If I understand you correctly, your problem is to re-render the DIV automatically. So there are a number of ways you can force an element to re-render (without a reload) - the most effective one I found was to quickly switch the display style of the element in question.

That is:

Set the display property to none:

element.style.display = 'none';

and then return it to block

element.style.display = 'block';

Here is the working demo of your example in JSFiddle.

Note: It's pure JavaScript.

于 2013-07-03T06:18:17.117 回答
0

你不能像那样只加载页面的一部分。但是您可以加载所有页面并仅获取您想要的部分。例如:

$.get('anoter_page.html',function(data){
myDiv = $(data).find('#divID');
$('#divID').html(myDiv.html());
})

示例:JSFiddle

于 2013-07-02T07:29:18.043 回答
0

这是一个示例,说明如何在不重新加载页面的情况下更新 div 的内容。有点不清楚你想从你的问题中得到什么,所以我希望这会有所帮助。

html

<div id="divID"></div>

javascript

var counter = 1;
var auto_refresh = setInterval(
function () {
    var newcontent= 'Refresh nr:'+counter;
    $('#divID').html(newcontent);
    counter++;
}, 1000);

现场示例在这里

于 2013-07-02T07:06:14.330 回答