Use setTimeout in js to write a time bomb

Source: Internet
Author: User
Today I am reading a blog post on the css exploration journey. I wrote a timer bomb using setTimeout, and I will write it as a cat. & Lt ;! DOCTYPEhtmlPUBLIC & quot;-// W3C // DTDXHTML1.0Transitional // EN & quot; http://www.w3.org/TR/xhtml1/DTD ..

Today I am reading a blog post on the css exploration journey. I wrote a timer bomb using setTimeout, and I will write it as a cat.
 




Untitled document


Start timing

Bomb Removal

Script
$ ("# Zha"). bind ("click", function (){
Zha ();
})
$ ("# Chai"). bind ("click", function (){
Chai ();
})
Var time = 5;
Var timer = 0;

Function zha (){
Var text = "Countdown ";
Text + = time --;
$ ("# Zha"). text (text );
If (time> = 0 ){
Timer = setTimeout (zha, 1000 );
$ ("# Zha" ).css ("color", "black ");
$ ("# Chai"). show ();
} Else {
$ ("# Zha"). text ("explosion ");
$ ("# Zha" ).css ("color", "red ");
Time = 5;
$ ("# Chai"). fadeOut ();
}
}

Function chai (){
ClearTimeout (timer );
$ ("# Zha"). text ("the bomb has been removed successfully, click Continue ");
}
Script


From jingangel
 

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.