反正就这个思路
function second(second) {
let day = parseInt(second / 60 / 60 / 24);
let hour = parseInt((second - day * 86400) / 60 / 60);
let min = parseInt((second - hour * 60 * 60 - day * 24 * 60 * 60) / 60);
let seconds = parseInt(
second - day * 24 * 60 * 60 - hour * 60 * 60 - min * 60
);
return { day, hour, min, second: seconds };
}
function render(data) {
for (const key in data) {
if (Object.hasOwnProperty.call(data, key)) {
if (data[key].toString().length < 2) {
data[key] = "0" + data[key];
}
}
}
const { day, hour, min, second } = data;
const spans = document.querySelectorAll("#jsCountdown span");
spans.forEach((item, index) => {
if (index === 0) {
+day === 0
? item.setAttribute("class", "hide")
: (item.innerHTML = day + "天");
}
if (index === 1) {
item.innerHTML = hour + ":";
}
if (index === 2) {
item.innerHTML = min + ":";
}
if (index === 3) {
item.innerHTML = second;
}
});
}