首頁  >  文章  >  web前端  >  js實作倒數時鐘的範例程式碼_javascript技巧

js實作倒數時鐘的範例程式碼_javascript技巧

WBOY
WBOY原創
2016-05-16 17:08:521268瀏覽

如下:

複製程式碼 程式碼如下:

if (document.all||document.getElementById)

document.write('')

window.onload=start_countdown

function countdown(){
var today=new Date()
var todayy=today.getYear()
if (todayy 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[mo-1] " " da ", " yr
futurestring=montharray[mo-1] " " da ", " yr
dd=Date.parse(futurestring)-Date.parse(todaystring)
dday=Math.floor(dd/(60*60*1000*24)*1)
dhour=Math.floor((dd %(60*60*1000*24))/(60*60*1000)*1)
dmin=Math.floor(((dd%(60*60*1000*24))%(60*60 *1000))/(60*1000)*1)
dsec=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))%(60* 1000))/1000*1)
if(ddayif (document.layers){
document. countdownnssub.document.write(opentags message_on_occasion closetags)
document.countdownnsmain.document.countdownnssub.document.close()
}return
}
else if (ddayif (document.layers){
(opentags "時間已經過了!" closetags)
document.countdownnsmain.document.countdownnssub.document.close()
}
else if (document.all||document.getElementBy}
else if (document.all||document.getElementBy)
crosscount .innerHTML=opentags "Occasion already passed! " closetags
return
}
else{
if (document.layers){
document.countns.document. dday " days, " dhour " hours, " dmin " minutes, and " dsec " seconds left until " occasion closetags)
document.countdownnsmain.document.countdownnssub.document.close()
}crosscount.innerHTML=opentags "還有" dday " 天, " dhour " 小時, " dmin " 分, " dsec " 秒就是" occasion closetags
}
setTimeout("countdown()",1000)
}




height="&{countdownheight};" width="&{countdownwidth};">id=countdownnssub height="&{countdownheight};"
width="&{countdownwidth};" top="0" left="0">



陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn