var
date =
new
Date(
"2020/1/1"
);
var
countDownDate = date.getTime();
var
target = document.getElementById(
'countdown'
);
target.style.fontSize =
'72px'
;
var
countDown =
function
(){
var
now =
new
Date().getTime();
var
distance = countDownDate - now;
var
days = Math.floor(distance / (1000 * 60 * 60 * 24));
var
hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60))
var
minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var
seconds = Math.floor((distance % (1000 * 60)) / 1000);
var
val =
days +
"日 "
+
hours +
"時間 "
+
minutes +
"分 "
+
seconds +
"秒 "
;
target.textContent = val;
}
$(
function
(){
var
updateTargetDate =
function
(){
var
name = $(
this
).attr(
'name'
);
var
y = Number($(
'[name="year"]'
).val());
var
m = Number($(
'[name="month"]'
).val());
var
d = Number($(
'[name="date"]'
).val());
var
dateFormat = [y, m, d].join(
'/'
);
date =
new
Date(dateFormat);
countDownDate = date.getTime();
}
$(
'input'
).on(
'change'
,
function
(){
updateTargetDate();
});
updateTargetDate();
countDown();
var
x = setInterval(
function
() {
countDown();
}, 1000);
})