javascript倒计时时间代码怎么写 比如在页面上显示3,2,1
- 提问者网友:容嬷嬷拿针来
- 2021-06-01 07:41
- 五星知识达人网友:愁杀梦里人
- 2021-06-01 08:50
<meta http-equiv="Page-Enter" content="revealTrans(duration=10, transition=4)">
<SCRIPT LANGUAGE="JavaScript">
var maxtime ="3";
function CountDown(){
if(maxtime>=0){
minutes = Math.floor(maxtime/60);
seconds = Math.floor(maxtime%60);
msg = "你的文字说明"+minutes+"分"+seconds+"秒";//动态显示剩余时间。
document.all["timer"].innerHTML=msg;
//if(maxtime == 3) document.all["timer"].innerHTML='只剩3秒!';
--maxtime;
}
else{
clearInterval(timer);
document.all["timer"].innerHTML='123';
}
}
timer = setInterval("CountDown()",1000);
</SCRIPT>
<div id=timer></div>
- 1楼网友:英雄的欲望
- 2021-06-01 08:59
简单的一种:
<script language="JavaScript"> var urodz= new Date("3/30/2005"); var s="离xx节日"; var now = new Date(); var ile = urodz.getTime() - now.getTime(); var dni = Math.floor(ile / (1000 * 60 * 60 * 24)); if (dni > 1) document.write(""+s+"还有"+dni +"天") else if (dni == 1) document.write("只有2天啦!") else if (dni == 0) document.write("只有1天啦!") else document.write("好象已经过了哦!"); </script>
复杂一些的:
<br>距离考试还有<br> <span id="span_dt_dt" ></span> <SCRIPT language=javascript> <!-- //document.write("");
function show_student163_time(){ window.setTimeout("show_student163_time()", 1000); BirthDay=new Date("04-01-2005");//改成你的计时日期 today=new Date(); timeold=(BirthDay.getTime()-today.getTime()); sectimeold=timeold/1000 secondsold=Math.floor(sectimeold); msPerDay=24*60*60*1000 e_daysold=timeold/msPerDay daysold=Math.floor(e_daysold); e_hrsold=(e_daysold-daysold)*24; hrsold=Math.floor(e_hrsold); e_minsold=(e_hrsold-hrsold)*60; minsold=Math.floor((e_hrsold-hrsold)*60); seconds=Math.floor((e_minsold-minsold)*60); span_dt_dt.innerHTML=daysold+"天"+hrsold+"小时"+minsold+"分"+seconds+"秒" ; } show_student163_time(); //--> </SCRIPT>