Javascript countdown source code. (hour. Minute. Second) detailed comment version

Source: Internet
Author: User

Write it casually! Bored! If the Code has bugs, you are welcome to make a strong shot!
JS CODE
Copy codeThe Code is as follows:
<Script type = "text/javascript" language = "javascript">
// Total time, divided into units
Var time = 100;
// Hour
Var h = parseInt (time/60)> 0? ParseInt (time/60): 0;
// Minute
Var m = time % 60;
// Second
Var s = 60;
// Output the Dom position to the current Script
Document. write ('<span> remaining <font id = "f_hh">' + h + '</font> hour <font id = "f_mm">' + m + '</ font> minute <font id = "f_ss"> '+ s +' </font> second </span> ');
// Start execution countdown
Var timeInterval = setInterval (function (){
// If the time, minute, and second are all 0, the current countdown will be stopped.
If (h = 0 & m = 0 & s = 0) {clearInterval (timeInterval); return ;}
// When the second reaches 0, it is 60 seconds again
If (s = 0) {s = 60 ;}
If (s = 60 ){
// Every time the second reaches 60 seconds, the minute minus one
M-= 1;
// When the minute is equal to 0 and the hour is more than one hour, go in and check it out.
If (m = 0 & h> 0 ){
// Subtract one hour
H-= 1;
// The default value is 60 minutes.
M = 60;
// The default value is 60 seconds.
S = 60;
}
}
// Continue to beat in seconds, minus one
S-= 1;
// Hourly value assignment
Document. getElementById ('f _ hh'). innerHTML = h;
// Minute value assignment
Document. getElementById ('f _ mm'). innerHTML = m;
// Second value assignment
Document. getElementById ('f _ ss'). innerHTML = s;
},1000 );
</Script>

HTML CODE
Copy codeThe Code is as follows:
<Html>
<Head>
<Title> Date Demo </title>
</Head>
<Body>
<Script type = "text/javascript" language = "javascript">
// Total time, divided into units
Var time = 100;
// Hour
Var h = parseInt (time/60)> 0? ParseInt (time/60): 0;
// Minute
Var m = time % 60;
// Second
Var s = 60;
// Output the Dom position to the current Script
Document. write ('<span> remaining <font id = "f_hh">' + h + '</font> hour <font id = "f_mm">' + m + '</ font> minute <font id = "f_ss"> '+ s +' </font> second </span> ');
// Start execution countdown
Var timeInterval = setInterval (function (){
// If the time, minute, and second are all 0, the current countdown will be stopped.
If (h = 0 & m = 0 & s = 0) {clearInterval (timeInterval); return ;}
// When the second reaches 0, it is 60 seconds again
If (s = 0) {s = 60 ;}
If (s = 60 ){
// Every time the second reaches 60 seconds, the minute minus one
M-= 1;
// When the minute is equal to 0 and the hour is more than one hour, go in and check it out.
If (m = 0 & h> 0 ){
// Subtract one hour
H-= 1;
// The default value is 60 minutes.
M = 60;
// The default value is 60 seconds.
S = 60;
}
}
// Continue to beat in seconds, minus one
S-= 1;
// Hourly value assignment
Document. getElementById ('f _ hh'). innerHTML = h;
// Minute value assignment
Document. getElementById ('f _ mm'). innerHTML = m;
// Second value assignment
Document. getElementById ('f _ ss'). innerHTML = s;
},1000 );
</Script>
</Body>
</Html>

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.