js网页倒计时代码如何到时间以后显示“时间已到”
我想让现在的效果显示为当倒计时结束以后显示“时间已到”,现在显示的是负数的时间,代码如下,如何加判断的语句<SPANid=span_dt_dt></SPAN><SCRIP...
我想让现在的效果显示为当倒计时结束以后显示“时间已到”,现在显示的是负数的时间,代码如下,如何加判断的语句
<SPAN id=span_dt_dt></SPAN>
<SCRIPT language=javascript>
<!--
//document.write("");
function show_date_time(){
window.setTimeout("show_date_time()", 1000); BirthDay=new Date("2014/7/4");//这个日期是可以修改的
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="据高考还有<align=center><p><font color=#A22900><p><font size=8>"+daysold+"天"+hrsold+"小时"+minsold+"分"+seconds+"秒"+"<br></font><br></font>" // 这里你自己改。就是倒计时的样式,字体大小size=4 颜色是
color
}
show_date_time();
//--> </SCRIPT> 展开
<SPAN id=span_dt_dt></SPAN>
<SCRIPT language=javascript>
<!--
//document.write("");
function show_date_time(){
window.setTimeout("show_date_time()", 1000); BirthDay=new Date("2014/7/4");//这个日期是可以修改的
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="据高考还有<align=center><p><font color=#A22900><p><font size=8>"+daysold+"天"+hrsold+"小时"+minsold+"分"+seconds+"秒"+"<br></font><br></font>" // 这里你自己改。就是倒计时的样式,字体大小size=4 颜色是
color
}
show_date_time();
//--> </SCRIPT> 展开
推荐于2018-02-28
展开全部
<!DOCTYPE HTML>
<html>
<head>
<title>yugi</title>
<meta charset=UTF-8 />
<style type="text/css">
#div {
color: #A22900;
font-size: 20px;
}
</style>
<script type="text/javascript">
var countdown = function ()
{
var reg = /^\d{2}$/;
var ending = new Date ("2016/6/7");
var now = new Date;
if (now >= ending)
{
clearTimeout(this.timeout);
div.innerHTML = "时间已到";
return;
}
var disc = ending - now;
var day = parseInt (disc / 1000 / 60 / 60 / 24);
var hour = parseInt (disc / 1000 / 60 / 60 % 24);
hour = !reg.test(hour) ? "0" + hour : hour;
var minute = parseInt (disc / 1000 / 60 % 60);
minute = !reg.test(minute) ? "0" + minute : minute;
var second = parseInt (disc / 1000 % 60);
second = !reg.test(second) ? "0" + second : second;
div.innerHTML = "距离高考还有<br / >" + day + "天" + hour + "小时" + minute + "分" + second + "秒";
this.timeout = setTimeout (countdown, 1000);
}
onload = countdown;
</script>
</head>
<body>
<div id="div"></div>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询