<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd> <Html xmlns = "http://www.w3.org/1999/xhtml"> <Head> <Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/> <Title> countdown test </title> <Script src = "jquery-1.6.2.min.js" type = "text/javascript"> </script> <Script> Function lxfEndtime (){ $ (". Lxftime"). each (function (){ Var lxfday = $ (this). attr ("lxfday"); // variable used to determine whether to display days Var endtime = new Date ($ (this). attr ("endtime"). getTime (); // Get the end date (millisecond value) Var nowtime = new Date (). getTime (); // Today's date (millisecond value) Var youtime = endtime-nowtime; // how long is there (millisecond value) Var seconds = youtime/1000; Var minutes = Math. floor (seconds/60 ); Var hours = Math. floor (minutes/60 ); Var days = Math. floor (hours/24 ); Var CDay = days; Var CHour = hours % 24; Var CMinute = minutes % 60; Var CSecond = Math. floor (seconds % 60 ); // "%" Indicates the remainder operation. It can be understood as 60 and then the remainder is obtained. If (endtime <= nowtime ){ Expires (this).html ("expired ") // If the end date is earlier than the current date, an expiration prompt is displayed. } Else { If ($ (this). attr ("lxfday") = "no "){ Expires (this).html ("<I> remaining time: </I> <span> "+ CHour +" </span> <span> "+ CMinute +" </span> <span> "+ CSecond +" </ span> seconds "); // Output data without days } Else { Expires (this).html ("<I> remaining time: </I> <span> "+ days +" </span> <em> day </em> <span> "+ CHour +" </span> <em> </em> <span> "+ CMinute +" </span> <em> Points </em> <span> "+ CSecond +" </span> <em> seconds </em> "); // Output data with days } } }); SetTimeout ("lxfEndtime ()", 1000 ); }; $ (Function (){ LxfEndtime (); }); </Script> <Style type = "text/css"> <! -- *{ Font-style: normal; Font-weight: normal ;} . Haveday { Padding: 20px; Border: 1px dashed #000; Margin-right: auto; Margin-left: auto; Width: 300px; } --> </Style> </Head> <Body> <Div class = "haveday"> <H1> countdown to days <Div class = "lxftime" endtime = "11/15/2015 17:24:0"> </div> <Div class = "lxftime" endtime = "11/8/2015 :3:20"> </div> <Div class = "lxftime" endtime = "9/6/2015 6:1:0"> </div> <Div class = "lxftime" endtime = "6/6/2016 :3:5"> </div> </Div> <P> </p> <Div class = "haveday"> <H1> No countdown to days <Div class = "lxftime" endtime = "11/15/2015 17:24:0" lxfday = "no"> </div> <Div class = "lxftime" endtime = "11/8/2015 :3:20" lxfday = "no"> </div> <Div class = "lxftime" endtime = "9/6/2015 6:1:0" lxfday = "no"> </div> <Div class = "lxftime" endtime = "6/6/2016 :3:5" lxfday = "no"> </div> </Div> </Body> </Html> |