Countdown effect, html countdown Effect

Source: Internet
Author: User

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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.