我正在使用jquery它在10秒后自动刷新,每次刷新它都会重复div一次并再次刷新两个div。
副本只发生一次..
代码:
<div class="tournament-users">
<span class="tournament_reg_teams_num">0/8></span>
</div>
js:
<script type="text/javascript">
var autoLoad = setInterval(
function ()
{
$('.tournament_reg_teams_num').load('normal-l.php .tournament_reg_teams_num').fadeIn(\"fast\");
}, 10000); // refresh page every 10 seconds
</script>
我10秒后得到的是:
<div class="tournament-users">
<span class="tournament_reg_teams_num">0/8></span>
<span class="tournament_reg_teams_num">0/8></span>
</div>
感谢您的帮助! :)
答案 0 :(得分:0)
在上传之前,您必须使用div
来刷新empty()
内容。
请尝试
$('.tournament-users').empty();
答案 1 :(得分:0)
尝试使用id而不是类。您也可以尝试为tournament_reg_teams_num
构建一个包装器并将其加载到该包装器中。
尝试类似这样的事情:
HTML
<div id="wrapper_tournament_reg_teams_num">
<span id="tournament_reg_teams_num">0/8</span>
</div>
JS
var autoLoad = setInterval(
function ()
{
$('#wrapper_tournament_reg_teams_num').load('normal-l.php #tournament_reg_teams_num').fadeIn(\"fast\");
}, 10000);
答案 2 :(得分:-1)
HTML:
<div class="test">
<div class="test2">test2</div>
</div>
JS:
var count = 0;
//function autoload : it return the setInterval function
var autoload = setInterval(function(){
//(You can do what you want here, depending on what you want to do)
count += 1;
//Here, I remove the content of "test" element
$('.test').empty();
//I create the new element and add it to "test" element
var element = $('<div></div>').addClass('test2').html('test2');
$('.test').append(element);
console.log(refresh);
}, 10000);
//If you have to stop the refresh
setTimeout(function(){
console.log('clearInterval');
clearInterval(autoload);
}, 6000)
这只是自动刷新的例子,希望它可以帮到你!