jquery倒计时
jquery倒计时,到0秒时返回指定的网址
<script>
var jq = {
countdown:function(countdom){
/*countdom:倒计时容器;
time:倒计时时间
*/
var count = $(countdom).text();//获得html中容器内的值
countdown = setInterval(function(){
$(countdom).html(count);
count--;
if (count < 0) {
clearTimeout(countdown)
window.location = 'http://www.liuhehu.com';
}
}, 1000);
}
}
$(function(){
jq.countdown("countdom");
})
</script>完整代码:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>首页</title>
<script type="text/javascript" src="http://www.liuhehu.com/wp-content/themes/sohodesign/js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="js/iehtml5.js"></script>
</head>
<body>
<div><span class="countdown">10</span>秒后返回首页</div>
<script>
var jq = {
countdown:function(countdom){
/*countdom:倒计时容器;
time:倒计时时间
*/
var count = $(countdom).text();//获得html中容器内的值
countdown = setInterval(function(){
$(countdom).html(count);
count--;
if (count < 0) {//小于0的原因是,当页面不能自动跳转时,停止在“0”。
clearTimeout(countdown)
window.location = 'http://www.liuhehu.com';
}
}, 1000);
}
};
$(function(){
jq.countdown(".countdown");
});
</script>
</body>
</html>效果:

本文作者: Jasmine
本文链接: https://www.jianbaizhan.com/article/501
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 3.0 许可协议。转载请注明出处!