-
Notifications
You must be signed in to change notification settings - Fork 0
/
calendarClock.js
65 lines (60 loc) · 1.92 KB
/
calendarClock.js
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
2018-8-16 wujy
功能:
用于显示日历和时钟
一旦时钟为0时0分0秒时更换日期
点击时钟可实现启动或暂停时钟
后期:
添加闹钟功能
*/
function showDate() {
var year = document.getElementsByClassName('year')[0];
var day = document.getElementsByClassName('day')[0];
var clock = document.getElementsByClassName('clock')[0];
//为日期加计时器
function calendarCom() {
var date = new Date();
var fullYear = date.getFullYear();
var dateDay = (date.getMonth() + 1) + "月" + date.getDate() + "日";
year.innerHTML = fullYear;
day.innerHTML = dateDay;
// console.log('我应该出现1次');
// return calendar;
}
calendarCom();
var calendar = setInterval(function() {
calendarCom();
}, 1000 * 60);
var calendar = calendarCom();
//为时钟加计时器
var clock1 = setInterval(function() {
var date = new Date();
var time = date.getHours() + "时" + date.getMinutes() + "分" + date.getSeconds() + "秒";
clock.innerHTML = time;
if (time == "8时21分40秒") {
clearInterval(calendar);
calendarCom();
calendar = setInterval(function() {
calendarCom();
}, 1000 * 60);
console.log('我被执行了,我只能出现1次');
}
}, 1000);
//当点击时启动或停止
clock.onclick = function() {
console.log('点击了吗?');
if (clock1) {
clearInterval(clock1);
console.log('stop');
clock1 = 0;
} else {
console.log('strat');
clock1 = setInterval(function() {
var date = new Date();
var time = date.getHours() + "时" + date.getMinutes() + "分" + date.getSeconds() + "秒";
clock.innerHTML = time;
}, 1000);
}
}
}
showDate();