首页 > 代码库 > 计数器方法使用?
计数器方法使用?
setInterval(f,1000); 设置计时器
clearInterval(screen_time); 清除计时器
<div class="cg_content">
<div class="success">
<img src="http://www.mamicode.com/images/success.png">
<span>恭喜您 注册成功!</span>
</div>
<p>页面将在 <b>5</b> 秒内自动跳转到<a href="javascript:void(0)" onclick="tiger();"> 微信首页</a></p>
</div>
<div class="zc_footer"></div>
<script type="text/javascript" src="http://www.mamicode.com/jquery-1.11.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var i = 5;
var f = function(){
i--;
$(".cg_content p b").text(i);
if(i == 0){
clearInterval(screen_time);
window.location=‘http://www.baidu.com‘;
}
// alert(screen_time);
}
var screen_time = setInterval(f,1000);
});
</script>
<script type="text/javascript">
function tiger(){
window.location=‘http://www.sina.com‘;
}
</script>
计数器方法使用?