html倒计时功能,html 和js 中实现倒计时功能

倒计时主要用到的知识点:1、设置时间间隔的setInterval可以被clearInterval取消

2、毫秒转换为时分格式

这个是效果图

6f1f30bcdc07d71077dfbf6813ff8711.png

下面是js中的函数

var shijian=3600;

var time=null;

function start(){

time=setInterval("count()",1000);//返回值time只是为了需要暂停的时候clearInterval(time)清除时间间隔

}

function count(){

if(shijian<0){

alert("time out");

pause();//一般情况下这个if条件是用来提交数据用的,这里只是测试一下。

}else{

$("#time p").html(Math.floor(shijian/60)+":"+shijian%60);//这里用到将毫秒转换到时分格式

shijian--;

console.info(time);

}

}

function pause(){

clearInterval(time);

}

function goOn(){

time = setInterval("count()",1000);//重新设置时间间隔

}

第二个是html资源,为了方便我css直接写在html中了

Document

input{

background-color: #9fc5f1;

width: 100px;

height: 30px;

line-height: 30px;

text-align: center;

color: #fff;

font-size:14px;

font-weight: bold;

}

#time p{

color: #1f6dc2;

font-size: 48px;

font-weight: bold;

margin-left:90px;

margin-bottom:0px;

}

00:00

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值