我的代码:
<div class="employee">
<div class="text">Number of Employees</div>
<div class="number">50</div>
</div>
我想要下面的div,每隔30秒替换上面的div。即上面的div显示30秒,然后下面的div显示30秒,然后返回上面的div 30秒,依此类推....
<div class="recruit">
<div class="text">Recruiting</div>
<div class="number">1</div>
</div>
我知道如何执行此操作 -
$( ".employee" ).click(function() {
$( this ).replaceWith( "<div class="recruit"><div class="text">Recruiting</div><div class="number">1</div></div>" );
});
但我不知道如何自动更改每30秒更换一次?
答案 0 :(得分:1)
您可以使用:
setInterval(function(){
if($('.employee').length)
$('.employee').replaceWith( '<div class="recruit"><div class="text">Recruiting</div><div class="number">1</div></div>' );
else
$('.recruit').replaceWith( '<div class="employee"><div class="text">Number of Employees</div><div class="number">50</div></div>' );
},30000);