Several lines of javascript code to implement the dynamic countdown Function

Source: Internet
Author: User

Js implements the dynamic countdown function * a is the timestamp received from the background, which must be converted to milliseconds
 

 
01
<Div>
02
There will be:
03
<Span id = 'day'> </span> days
04
<Span id = 'ursa '> </span> hour
05
<Span id = 'minua '> </span>
06
<Span id = 'secoa '> </span> seconds
07
</Div>
08
<Script type = "text/javascript">
09
/**
10
*
11
* Copyright Liu Xiaobo 2012.7
12
* Js implements the dynamic countdown Function
13
* A is the timestamp received from the background, which must be converted to the unit of milliseconds.
14
*
15
*/
16
Var a = 12345678; // in milliseconds
17
Function fomtime ()
18
{
19
A = a-1000;
20
Var B = new Date ();
21
B. setTime (0 );
22
Var c = new Date ();
23
C. setTime ();
24
Var day1 = B. getDate (); // for convenient calling, separate the days and hours
25
Var hours1 = B. getHours ();
26
Var minu1 = B. getMinutes ();
27
Var seco1 = B. getSeconds ();
28
Var day2 = c. getDate ();
29
Var hours2 = c. getHours ();
30
Var minu2 = c. getMinutes ();
31
Var seco2 = c. getSeconds ();
32
Var day = day2-day1;
33
Var hours = hours2-hours1;
34
Var minu = minu2-minu1;
35
Var seco = seco2-seco1;
36
Document. getElementById ('daya'). innerHTML = day;
37
Document. getElementById ('ursa '). innerHTML = hours;
38
Document. getElementById ('minua '). innerHTML = minu;
39
Document. getElementById ('secaca'). innerHTML = seco;
40
SetTimeout ("fomtime ()", 1000 );
41
}
42
Fomtime ();
43
</Script>


Author: The power of dedication

Related Article

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.