-
Notifications
You must be signed in to change notification settings - Fork 2
/
新jquery倒计时.html
38 lines (29 loc) · 1.51 KB
/
新jquery倒计时.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<html>
<head>
<meta charset="utf-8" />
<title>jquery倒计时</title>
<script src="jquery-1.11.1.js"></script>
<script>
$(function () {
var interval = setInterval(function () {
var now = new Date().getTime();
var end = new Date("2018/7/1/ 0:48:00");//结束的时间:年,月,日,分,秒(月的索引是0~11)
var result = end - now;/*两个时间相减,得到的是毫秒ms,变成秒*/
if (result > 1) {
var second = parseInt(result/1000%60); // 计算秒 ,取余
var minite = parseInt(result/1000/60%60); //计算分 ,换算有多少分,取余,余出多少秒
var hour = parseInt(result/1000/3600%24); //计算小时,换算有多少小时,取余,24小时制除以24,余出多少小时
var day = parseInt(result/1000/3600/24); //计算天 ,换算有多少天
$("#remainTime").html(day + "天" + hour + "小时" + minite + "分" + second + "秒");
} else {
window.clearInterval(interval); //这里可以添加倒计时结束后需要执行的事件
alert("倒计时结束!");
}
},1000);
});
</script>
</head>
<body>
<div id="remainTime" style="font-size:20px;font-weight:800;color:#FF9900"></div>
</body>
</html>