我正在使用我在互联网上找到的一些代码,该代码从某个日期开始倒计时。我正在尝试编辑代码,以便它只给我一个从未来日期指定的小时、分钟和秒的倒计时。我不能只拥有从指定时间倒计时的代码,我需要它倒计时到未来的指定日期。这很重要,因此如果刷新浏览器,倒计时不会重新开始,而是从中断的地方继续。我将使用 cookie,以便浏览器记住第一次运行时指定的未来日期。
这是HTML:
<form name="count">
<input type="text" size="69" name="count2">
</form>
这是javascript:
window.onload = function() {
//change the text below to reflect your own,
var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
function countdown(yr,m,d){
var theyear=yr; var themonth=m; var theday=d
var today=new Date()
var todayy=today.getYear()
if (todayy < 1000)
todayy+=1900;
var todaym=today.getMonth()
var todayd=today.getDate()
var todayh=today.getHours()
var todaymin=today.getMinutes()
var todaysec=today.getSeconds()
var todaystring=montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec
futurestring=montharray[m-1]+" "+d+", "+yr
var dd=Date.parse(futurestring)-Date.parse(todaystring)
var dday=Math.floor(dd/(60*60*1000*24)*1)
var dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1)
var dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1)
var dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1)
if(dday==0&&dhour==0&&dmin==0&&dsec==1){
document.forms.count.count2.value=current
return
}
else
document.forms.count.count2.value= dhour+":"+dmin+":"+dsec;
setTimeout(function() {countdown(theyear,themonth,theday)},1000)
}
//enter the count down date using the format year/month/day
countdown(2012,12,25)
}
我确信上面有多余的代码,因为我只需要一个小时、分钟和秒来传递给countdown()
函数。年、月和日并不重要,但正如我所说,这是我正在尝试编辑的代码,我在互联网上找到。任何帮助将不胜感激。谢谢!