概述
html==================================
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="./damo1.css">
<link rel="stylesheet" href="./geshi.css">
</head>
<body>
<div>
<h2>距离双十二</h2>
<p>还有</p>
<ul>
<li class="tian"><input type="text" id="txt1"></li>
<li class="shi"><input type="text" id="txt2"></li>
<li class="fen"><input type="text" id="txt3"></li>
<li class="miao"><input type="text" id="txt4"></li>
</ul>
</div>
</body>
</html>
<script src="./demo.js"></script>
css================================
div{
width: 250px;
height: 300px;
background: rgb(245, 139, 139);
}
div h2{
text-align: center;
line-height: 60px;
font-size: 20px;
color: white;
}
div p{
text-align: center;
}
div ul li{
width: 45px;
height: 45px;
background: rgb(46, 46, 46);
float: left;
margin-left: 10px;
margin-top: 80px;
color: white;
text-align: center;
}
div ul{
float: left;
display: flex;
}
div ul input{
width: 100%;
height: 100%;
display: block;
text-align: center;
}
js=====================================
function getCha(date1, date2) {
var date2 = new Date();
var cha = date1.getTime() - date2.getTime();//毫秒
var s = parseInt(cha / 1000 % 60);
var m = parseInt(cha / 1000 / 60 % 60);
var h = parseInt(cha / 1000 / 60 / 60 % 24)
var t = parseInt(cha / 1000 / 60 / 60 / 24)
s = s < 10 ? '0' + s : s;
m = m < 10 ? '0' + m : m;
h = h < 10 ? '0' + h : h;
oTxt1.value = t + '天'
oTxt2.value = h + '小时'
oTxt3.value = m + '分钟'
oTxt4.value = s + '秒'
}
var oTxt1 = document.getElementById('txt1')
var oTxt2 = document.getElementById('txt2')
var oTxt3 = document.getElementById('txt3')
var oTxt4 = document.getElementById('txt4')
setInterval(function () {
var date1 = new Date('2022-01-01 00:00:00');
var date2 = new Date();
getCha(date1, date2)
}, 1000);
最后
以上就是风趣大门为你收集整理的js实现双十二倒计时的全部内容,希望文章能够帮你解决js实现双十二倒计时所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复