求HTML代码倒计时
发布网友
发布时间:2022-05-13 16:11
我来回答
共2个回答
热心网友
时间:2023-10-15 17:12
实时倒计时代码,可以设定期限!
<!--单位:秒-->
剩余时间:<span id="endtime">10</span>
<script type="text/javascript">
var CID = "endtime";
if(window.CID != null)
{
var iTime = document.getElementById(CID).innerText;
var Account;
RemainTime();
}
function RemainTime()
{
var iDay,iHour,iMinute,iSecond;
var sDay="",sHour="",sMinute="",sSecond="",sTime="";
if (iTime >= 0)
{
iDay = parseInt(iTime/24/3600);
if (iDay > 0)
{
sDay = iDay + "天";
}
iHour = parseInt((iTime/3600)%24);
if (iHour > 0){
sHour = iHour + "小时";
}
iMinute = parseInt((iTime/60)%60);
if (iMinute > 0){
sMinute = iMinute + "分钟";
}
iSecond = parseInt(iTime%60);
if (iSecond >= 0){
sSecond = iSecond + "秒";
}
if ((sDay=="")&&(sHour=="")){
sTime="<span style='color:darkorange'>" + sMinute+sSecond + "</font>";
}
else
{
sTime=sDay+sHour+sMinute+sSecond;
}
if(iTime==0){
clearTimeout(Account);
sTime="<span style='color:green'>时间到了!</span>";
}
else
{
Account = setTimeout("RemainTime()",1000);
}
iTime=iTime-1;
}
else
{
sTime="<span style='color:red'>倒计时结束!</span>";
}
document.getElementById(CID).innerHTML = sTime;
}
</script>
</body>
</html>
热心网友
时间:2023-10-15 17:12
<html>
<script language="JavaScript">
<!-- hide script from old browser
var DifferenceHour = -1
var DifferenceMinute = -1
var DifferenceSecond = -1
var Tday = new Date("June 30, 2010 23:59:59") //**倒计时时间点-注意格式.这里可以自己设定日期
var daysms = 24 * 60 * 60 * 1000
var hoursms = 60 * 60 * 1000
var Secondms = 60 * 1000
var microsecond = 1000
function clock()
{
var time = new Date()
var hour = time.getHours()
var minute = time.getMinutes()
var second = time.getSeconds()
var timevalue = ""+((hour > 12) ? hour-12:hour)
timevalue +=((minute < 10) ? ":0":":")+minute
timevalue +=((second < 10) ? ":0":":")+second
timevalue +=((hour >12 ) ? " PM":" AM")
// document.formnow.now.value = timevalue
var convertHour = DifferenceHour
var convertMinute = DifferenceMinute
var convertSecond = DifferenceSecond
var Diffms = Tday.getTime() - time.getTime()
DifferenceHour = Math.floor(Diffms / daysms)
Diffms -= DifferenceHour * daysms
DifferenceMinute = Math.floor(Diffms / hoursms)
Diffms -= DifferenceMinute * hoursms
DifferenceSecond = Math.floor(Diffms / Secondms)
Diffms -= DifferenceSecond * Secondms
var dSecs = Math.floor(Diffms / microsecond)
if(convertHour != DifferenceHour) document.formnow.dd.value=DifferenceHour
if(convertMinute != DifferenceMinute) document.formnow.hh.value=DifferenceMinute
if(convertSecond != DifferenceSecond) document.formnow.mm.value=DifferenceSecond
document.formnow.ss.value=dSecs
// document.formnow.Tnow.value= DifferenceHour DifferenceMinute + DifferenceSecond + dSecs
setTimeout("clock()",1000)
}
// end hiding -->
</script>
<body onload="clock();"><!--实现显示-->
距离2010年7月1日还有:
<form name="formnow">
<input name="dd" type="text" style="border:0;" size=2>
天
<input name="hh" type="text" style="border:0;" size=2>
小时
<input name="mm" type="text" style="border:0;" size=2>
分
<input name="ss" type="text" style="border:0;" size=2>
秒
</form>
</body>
</html>