Javascript 每10秒刷新一次div复制div
我使用jquery,它会在10秒后自动刷新,每次刷新它都会复制div一次,然后再次刷新两个div 重复只发生一次 代码:Javascript 每10秒刷新一次div复制div,javascript,php,jquery,html,Javascript,Php,Jquery,Html,我使用jquery,它会在10秒后自动刷新,每次刷新它都会复制div一次,然后再次刷新两个div 重复只发生一次 代码: 0/8> js: var autoLoad=setInterval( 函数() { $('.tournal\u reg\u teams\u num').load('normal-l.php.tournal\u reg\u teams\u num').fadeIn(\“fast\”); }, 10000); // 每10秒刷新一次页面 10秒后我得到的是:
0/8>
js:
var autoLoad=setInterval(
函数()
{
$('.tournal\u reg\u teams\u num').load('normal-l.php.tournal\u reg\u teams\u num').fadeIn(\“fast\”);
}, 10000); // 每10秒刷新一次页面
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/8>
0/8>
谢谢你的帮助!:) 在显示之前,必须使用
empty()
刷新div
内容
请试一试
$('.tournament-users').empty();
尝试使用id而不是类。您还可以尝试为您的
锦标赛\u reg\u团队\u num
构建一个包装器,并将其加载到其中
尝试以下方法,例如:
HTML
HTML:
测试2
JS:
var计数=0;
//函数自动加载:返回setInterval函数
var autoload=setInterval(函数(){
//(你可以在这里做你想做的事,这取决于你想做什么)
计数+=1;
//在这里,我删除了“test”元素的内容
$('.test').empty();
//我创建新元素并将其添加到“test”元素中
var元素=$('').addClass('test2').html('test2');
$('.test')。追加(元素);
控制台日志(刷新);
}, 10000);
//如果你必须停止刷新
setTimeout(函数(){
console.log('clearInterval');
clearInterval(自动加载);
}, 6000)
这只是一个自动刷新的例子,希望能对你有所帮助 $('.touring\u reg\u teams\u num').load('normal-l.php.touring\u reg\u teams\u num').fadeIn(\“fast\”)代码>为什么调用php后会有一个类?有必要吗?
<div class="tournament-users">
<span class="tournament_reg_teams_num">0/8></span>
<span class="tournament_reg_teams_num">0/8></span>
</div>
$('.tournament-users').empty();
<div id="wrapper_tournament_reg_teams_num">
<span id="tournament_reg_teams_num">0/8</span>
</div>
var autoLoad = setInterval(
function ()
{
$('#wrapper_tournament_reg_teams_num').load('normal-l.php #tournament_reg_teams_num').fadeIn(\"fast\");
}, 10000);
<div class="test">
<div class="test2">test2</div>
</div>
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)