当前位置:网站首页>js全局计时器的案例
js全局计时器的案例
2022-06-10 11:55:00 【000000001111】
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>计时器</title>
<style>
* {
margin: 0;
padding: 0;
}
#box {
width: 400px;
height: 400px;
margin: 40px auto;
}
#box div {
width: 200px;
height: 40px;
border: 1px #F3C solid;
text-align: center;
float: left;
font-size: 26px;
}
#box button {
float: left;
margin-top: 10px;
margin-left: 20px;
}
#box span {
float: left;
width: 200px;
height: 100px;
overflow-y: auto;
display: block;
border: 1px #C9C solid;
margin-top: 10px;
}
</style>
</head>
<body>
<div id="box">
<div id="timer"></div>
<button onClick="btTime()">开始服务</button>
</div>
<script type="text/javascript">
var timer = document.getElementById("timer");
var butt = document.getElementsByTagName("button");
var hour = '00'; //时
var minus = '00'; //分
var seconds = '00'; //秒
timer.innerHTML = hour + ":" + minus + ":" + seconds;
var x = 0,
y = 0,
f = 0,
a = 0,
b = 0,
t1, t2;
var flag = 0;
function btTime() {
/*ajax:*/
switch (flag) {
case 0:
flag = 1;
w = 1;
t1 = setInterval(beginS, 1000);
butt[0].innerHTML = '结束服务';
break;
case 1:
flag = 2;
clearInterval(t1);
butt[0].innerHTML = '服务已结束';
break;
}
}
function beginS() {
//计算秒
x++;
if (x < 10) {
seconds = '0' + x;
} else if (x >= 10 && x <= 59) {
seconds = x;
} else if (x > 59) {
seconds = '00';
x = 0;
a++;
}
if (a < 10) {
minus = '0' + a;
} else if (a >= 10 && a <= 59) {
minus = a;
} else if (a > 59) {
minus = '00';
a = 0;
b++;
}
if (b < 10) {
hour = '0' + b;
} else if (b >= 10 && b <= 59) {
hour = b;
}
timer.innerHTML = hour + ":" + minus + ":" + seconds;
}
</script>
</body>
</html>
具体详情请查看原文链接。
转载:感谢分享
原文链接:https://wangxiaoting.blog.csdn.net/article/details/82456877?spm=1001.2014.3001.5502

边栏推荐
- Clip usage
- 【必备】,真题解析
- Unity打字机,使文本自动滚至文本框底部
- 87. (leaflet house) leaflet military plotting - straight arrow modification
- Opérations de haut niveau du capteur de pythorch
- Transfomer各组件与Pytorch
- [yuntu Said] chaque système d'affaires réussi ne peut pas être séparé de l'escorte de l'apig
- "Yi +" open source program - Design and practice of low delay player based on webrtc
- 浅谈分布式事务
- CLIP使用
猜你喜欢

更改系统时间

Cvpr22 oral | Hong Kong Chinese proposed transrank: sequencing loss + self supervision =sota
![[extensive reading of papers] distilling the knowledge in a neural network](/img/e3/b834c60364741d671ce07ee8eedf95.png)
[extensive reading of papers] distilling the knowledge in a neural network

【 ten thousand people single wooden bridge 】 how to arrange life in that summer after the college entrance examination?

Massive data: the first stock of Huawei Gauss database (depth)

入门篇:从 etcd 名字的由来,到安装部署和使用姿势

B站教学 手把手教你使用YOLOV5之口罩检测项目 最全记录详解 ( 深度学习 / 目标检测 / pytorch )

Practice of Flink CDC in Dajian cloud warehouse

十三、系统调用和Shell(freestanding shell, 终端和 job control)

嵌入式Linux中使用SQLite3数据库
随机推荐
Pytorch tensor高階操作
CLIP使用
Long term learning of graphic and text pre training.
OAuth2学习中的一些高频问题的QA
web服务器开发,小型公司web开发
Practice of Flink CDC + Hudi massive data entering the lake in SF
怎样将PDF作为矢量图插入PPT中
B站教学 手把手教你使用YOLOV5之口罩检测项目 最全记录详解 ( 深度学习 / 目标检测 / pytorch )
Xijun data cooperates with Alibaba cloud to obtain Alibaba cloud product integration certification!
CLIP使用
线性代数的本质4 矩阵乘法与线性复合变换
在启牛开户证券安全吗
Transfomer components and pytoch
Localdatetime and string date conversion
QA of some high frequency problems in oauth2 learning
shape颜色渐变、圆角、半圆角、边框、填充
0509-130 Symbol resolution failed for /oracle/app/oracle/12.2.0/db_ 1/lib/libons. So problem handling
Do not concatenate text displayed with setText,use resource string with placeholders.
Transfomer自实现与官方库
Surrender firehouse database access: Twitter is ready to meet Musk's requirements