A few days ago the eldest brother said himself to write the countdown, but today is still divided into my hand.
The effect is still good. There is no online, or to provide connectivity to reader to see the effect of the countdown JS.
| The code is as follows |
Copy Code |
<script> Window.onload=countdown (); function countdown (time) { var DJs = time; var b=math.round (new Date (). GetTime ()/1000); var cc = Djs-b; var d = Math.floor (cc/(3600*24)); var h = Math.floor ((cc-d*3600*24)/3600); var m = Math.floor (((cc-d*3600*24-h*3600))/60); var s = math.floor (cc-d*3600*24-h*3600-m*60); $ (' #daya '). html (d); $ (' #hoursa '). html (h); $ (' #minua '). html (m); $ (' #secoa '). HTML (s); SetTimeout ("Countdown ()", 1000); }
</script>
|
The code is still relatively streamlined. See the Internet a big push JS countdown. But there is no one for you. Just refer to someone else's own written JS Countdown code
Attached to the learning process with the search to the countdown code
| The code is as follows |
Copy Code |
| <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/> <TITLE>JS Implementation Countdown (time, minutes, sec) </title> <script language= "javascript" type= "Text/javascript" > var interval = 1000; function Showcountdown (year,month,day,divname) { var now = new Date (); var enddate = new Date (year, month-1, day); var lefttime=enddate.gettime ()-now.gettime (); var leftsecond = parseint (lefttime/1000); var day1=parseint (leftsecond/(24*60*60*6)); var Day1=math.floor (leftsecond/(60*60*24)); var Hour=math.floor ((leftsecond-day1*24*60*60)/3600); var Minute=math.floor ((leftsecond-day1*24*60*60-hour*3600)/60); var second=math.floor (leftsecond-day1*24*60*60-hour*3600-minute*60); var cc = document.getElementById (divname); cc.innerhtml = "The script house prompts the distance" +year+ "The Year" +month+ "the Month" +day+ "The Day also has:" +day1+ "the Day" +hour+ "The Hour" +minute+ "The Minute" +second+ "the second"; } Window.setinterval (function () {Showcountdown (2010,4,20, ' divdown1 ');}, Interval); </script> <body> <div id= "Divdown1" ></div> </body>
|
Example 2
| The code is as follows |
Copy Code |
| <script type= "Text/javascript" > Startclock (); var timerid = null; var timerrunning = false; function Showtime () { Today = new Date (); var year = Today.getfullyear (); document.getElementById ("Next_yeat"). InnerHTML = year + 1; var nowhour = today.gethours (); var nowminute = Today.getminutes (); var nowmonth = Today.getmonth (); var nowdate = Today.getdate (); var nowyear = Today.getyear (); var nowsecond = Today.getseconds (); if (Nowyear <2000) Nowyear=1900+nowyear; today = NULL; Hourleft = 23-nowhour Minuteleft = 59-nowminute Secondleft = 59-nowsecond Yearleft = Year-nowyear Monthleft = 12-nowmonth-1 Dateleft = 31-nowdate if (secondleft<0) { Secondleft=60+secondleft; minuteleft=minuteleft-1; } if (minuteleft<0) { Minuteleft=60+minuteleft; hourleft=hourleft-1; } if (hourleft<0) { Hourleft=24+hourleft; dateleft=dateleft-1; } if (dateleft<0) { Dateleft=31+dateleft; monthleft=monthleft-1; } if (monthleft<0) { Monthleft=12+monthleft; yearleft=yearleft-1; } temp=yearleft+ ' year, ' +monthleft+ ' month, ' +dateleft+ ' Day, ' +hourleft+ ' hour, ' +minuteleft+ ' minutes, ' +secondleft+ ' seconds '; Document.form1.left.value=temp; Timerid = settimeout ("Showtime ()", 1000); Timerrunning = true; } var timerid = null; var timerrunning = false; function Stopclock () { if (timerrunning) Cleartimeout (Timerid); Timerrunning = false; } function Startclock () { Stopclock (); Showtime (); } --> </script> |
Finally this is my reference to write a
| The code is as follows |
Copy Code |
| <div Id= "M1" ></div> <script type= "Text/javascript" > Window.onload=function () {Daojishi ()}; Function Daojishi () { var day=hour=minitus=second=ms=0; var year=new Date (). getFullYear () +1; var endtime = new Date (year,0,1);//End time var todaytime = new Date (); //Current time ; var tmp=endtime-todaytime; Day=math.floor (tmp/86400000); tmp= (new Date (year,0,1)-new date ())%86400000; Hour=math.floor (tmp/3600000); tmp%=3600000; Minitus=math.floor (tmp/60000); tmp%=60000; Second=math.floor (tmp/1000); var str = "Distance" +year+ "year" and "+day+" +hour+ "Hour" +minitus+ "Min" +second+ "seconds"; document.getElementById ("M1"). innerhtml= str; settimeout ("Daojishi ()", 1000); } </script> |
Displayed from 2014 35 days 8 hours 26 minutes 47 seconds