Countdown effect, html countdown Effect
Task requirements:
- The interface first has a text input box that allows you to enter the year, month, and day in a specific format YYYY-MM-DD;
- There is a button next to the input box. click the button to calculate the time difference between the current 00:00:00 and the input date.
- The page shows that there are still XX days, XX hours, XX minutes, and XX seconds from mm dd, YYYY.
- Update the number displayed on the countdown every second
- If the time difference is 0, the countdown stops.
Html file code:
<! DOCTYPE html>
Task0002_2.js code:
/** Author: Zhao shaobang * Date: 2014-6-5 */function $ (selector) {return document. querySelector (selector);} function IsDate (str) {var reg =/^ (\ d {4})-(\ d {2})-(\ d {2 }) $/; if (str = '') {return false;} var arr1_reg.exe c (str); if (! Reg. test (str) | parseInt (RegExp. $2)> = 12 | parseInt (RegExp. $3) >=31) {return false;} return true;} function timer (date) {var ts = date-new Date (); // calculate the remaining milliseconds var dd = parseInt (ts/1000/60/60/24, 10); // calculate the remaining days var hh = parseInt (ts/1000/60/60% 24, 10); // calculate the remaining hours var mm = parseInt (ts/1000/60% 60, 10); // calculate the remaining minutes var ss = parseInt (ts/1000% 60, 10); // calculate the remaining number of seconds dd = checkTime (dd); hh = checkTime (hh); mm = checkTime (mm); ss = checkTime (ss ); $ ('# result '). innerHTML = 'and' + dd + 'day' + hh + 'hour' + mm + 'Min' + ss + 'second '; if (dd = '00' & hh = '00' & mm = '00' & ss = '00') {return 1 ;} function checkTime (t) {if (t <10) {return '0' + t;} return t ;}}
Running effect: