functiongetQueryVariable(variable){ let query = window.location.search.substring(1); let vars = query.split("&"); for (let i=0;i<vars.length;i++) { let pair = vars[i].split("="); if(pair[0] == variable){return pair[1];} } return(false); } window.addEventListener("load", () => { const day = document.querySelector(".day"); const hour = document.querySelector(".hour"); const minute = document.querySelector(".minute"); const second = document.querySelector(".second"); if(decodeURI(getQueryVariable("mode"))=="light") change(2); elsechange(1); constgetTime = () => { var date_0=newDate; var year_0=date_0.getFullYear(); var month_0=date_0.getMonth(); var day_0=date_0.getDate(); if(month_0>6||(month_0=6&&day_0>6)){ year_0=year_0+1; } varYMDT=year_0.toString()+"/06/07 09:00"; varEndTime=newDate(YMDT); var name="高考"; if(getQueryVariable("date")==false||getQueryVariable("time")==false||getQueryVariable("name")==false) EndTime= newDate(YMDT),name="高考"; elseEndTime= newDate(getQueryVariable("date")+" "+getQueryVariable("time")),name=decodeURI(getQueryVariable("name")); document.getElementById("name").innerHTML="距离"+decodeURI(name)+"还有"; document.getElementById("title").innerHTML=name+"倒计时"; varNowTime = newDate(); var t =EndTime.getTime() - NowTime.getTime(); if(t<0) EndTime= newDate(YMDT),name="高考",t =EndTime.getTime() - NowTime.getTime(); const days = Math.floor(t/1000/60/60/24); day.innerHTML = days < 100 ? (days<10? "00"+days: "0"+days) : days; const hours = Math.floor(t/1000/60/60%24); hour.innerHTML = hours < 10 ? "0" + hours : hours; const minutes = Math.floor(t/1000/60%60); minute.innerHTML = minutes < 10 ? "0" + minutes : minutes; const seconds = Math.floor(t/1000%60); second.innerHTML = seconds < 10 ? "0" + seconds : seconds; var pass = Math.floor(((NowTime.getTime() / 1000) + 28800) % 86400) / 864; pass = pass.toFixed(2); document.getElementById("progress").value=pass; document.querySelector(".data>span").innerHTML=pass+" % "; }; getTime(); let timer = setInterval(() => { getTime(); }, 1000); }); functionchange(a){ var css=document.getElementById("css"); if (a == 1) { css.setAttribute("href","https://codes.luyaoguagua.top/timer/css/night.css"); } if (a == 2) { css.setAttribute("href","https://codes.luyaoguagua.top/timer/css/light.css"); } }
用到的语法
var
1 2 3 4 5 6
var date_0=newDate; var year_0=date_0.getFullYear(); var month_0=date_0.getMonth(); var day_0=date_0.getDate(); varYMDT=year_0.toString()+"/06/07 09:00"; varEndTime=newDate(YMDT);