当前位置:网站首页>Write a program to realize the effect of automatic movement of the electronic clock, and provide a button to control whether the electronic clock stops moving.
Write a program to realize the effect of automatic movement of the electronic clock, and provide a button to control whether the electronic clock stops moving.
2022-04-22 23:13:00 【Did you add pepper?】
subject :
Programming , Realize the effect of automatic movement of the electronic clock, and provide a button to control whether the electronic clock stops moving .
Code interpretation :
chance_str(n) function : Format the acquired time , That is, fill zero for one digit less than two digits .
time() function : Acquisition time , newly build Date Object returns the date and time of the current day . among setTimeout Refresh time per second .
chance() function : Control buttons
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<div id="text">
<p id="time"></p>
<input type="button" id="bian" onclick="chance()" value=" Pause ">
</div>
<script>
// Programming , Realize the effect of automatic movement of electronic clock ,
// A button is provided to control whether the electronic clock stops moving .
// Clear procedure steps are required , And annotate the program .
var run = true; // Control whether time moves
function chance_str(n){
// Zero padding for two digits
if (n<10){
n = "0" + n
}
return n
}
function time(){
// Acquisition time
//console.log(run)
if(run){
var day = new Date();
var h = day.getHours();// Zero padding for two digits
h = chance_str(h)
var m = day.getMinutes();// Zero padding for two digits
m = chance_str(m)
var s = day.getSeconds();// Zero padding for two digits
s = chance_str(s)
document.getElementById('time').innerHTML =
h + ":" + m + ":" + s;
setTimeout(time, 1000); // Refresh time per second
}
}
time() // Call the time function , Initialization interface
function chance(){
// Control button events
if(run == true){
// Suspend operation
run = !run;
document.getElementById('bian').value = " Start ";
}else{
// Start the operation
run = !run;
document.getElementById('bian').value = " Pause ";
time()
}
}
</script>
</body>
</html>
Screenshot of operation result :

That's it , A very simple code , Main understanding Date The object is !!!
The running time is like my time ! If you let me add a limit , I hope it's ten thousand years !!!

版权声明
本文为[Did you add pepper?]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204222309549409.html
边栏推荐
- 从proc查询uid
- GBase 8a常用并行度参数调整提升性能
- Chenshi industrial machine vision | weld detection solution
- Login function & test point extraction of new article function and test case writing
- 【Vmware】Vmware ESXI 6.7 安装
- Yolov1 paper notes
- Where is London gold safer to open an account?
- Shell script command results are saved to variables with line breaks
- js中对Array进行遍历
- Online yaml to XML tool
猜你喜欢
![[BJDCTF2020]Easy MD5](/img/94/08b19ead7c48549340b29bc8f34033.png)
[BJDCTF2020]Easy MD5

SystemVerilog 验证-测试平台编写指南学习笔记(3):连接设计和测试平台

Introduction to encryption mode (ECB, CBC, PCBC, CFB, OFB, CTR)

Canal使用流程、部署安装文档

(JS)利用String对象的属性和方法实现注册和登录功能,要求用户名长度在3-10范围内,密码在6-20位
![[swift] code triggers uibutton click event](/img/23/444cfab44afe32d0476ba26f64bfdf.png)
[swift] code triggers uibutton click event

Detailed explanation of SQL language

如何看待、快手、知乎等平台将上线显示用户IP属地功能?

mysql索引详解

【Vmware】Vmware ESXI 6.7 安装
随机推荐
An open source scripting scheme for quickly tracking close contacts
[reproduction of thesis code] errors encountered in the translation embeddings for modeling multi relational data
django连接数据库获取数据
Le Code [SWIFT] déclenche l'événement de clic d'uibutton
Numeric type and sequence type
Basic use and principle of Minio
Read software engineering at Google (13)
Go timer time Ticker
Pytorch convolution kernel filling and stride, multiple input and multiple output channels, pool layer
JS有红,白,黑三球若干个,其中红,白球共25个,白黑共31个,红黑共28个,求三种球各多少个。
SystemVerilog 验证-测试平台编写指南学习笔记(3):连接设计和测试平台
SQL语言详解
解决require is not defined的报错问题
Go language learning notes - read lock reentry leads to deadlock
L1-049 ladder race seat allocation (20 points) (in-depth understanding of for loop + three-dimensional array + error analysis)
AcWing 1842. 牛奶桶 遍历所有情况
记录使用PageHelper时,使用Example添加排序失效问题
如何看待、快手、知乎等平台将上线显示用户IP属地功能?
LeetCode 414. 第三大的数(简单、数组)day13
Read software engineering at Google (14)