Js implementation countdown button instance _ javascript skills

Source: Internet
Author: User
This article mainly introduces the countdown button for js implementation. The example analyzes the implementation skills related to the countdown effect for javascript. if you need it, refer to the example in this article to describe the countdown button for js implementation. Share it with you for your reference. The specific analysis is as follows:

As follows:

The code is as follows:

 
 
  
Var secs = 3; var wait = secs * 1000; var update = function (num, value) {if (num = (wait/1000 )) {$ ("# rulesubmit "). val ("Get Free");} else {printnr = (wait/1000)-num; $ ("# rulesubmit "). val ("Get Free (" + printnr + ")") ;}}; var timer = function () {$ ("# rulesubmit "). attr ("disabled", false); $ ("# rulesubmit "). val ("Get Free") ;};$ (function () {function getValidateCode () {$ ("# rulesubmit "). val ("get for free (" + secs + ")"); $ ("# rulesubmit "). attr ("disabled", true); for (I = 1; I <= secs; I ++) {window. setTimeout ("update (" + I + ")", I * 1000);} window. setTimeout ("timer ()", wait) ;}$ ("# rulesubmit "). click (function () {getValidateCode () ;}) ;}(); // Note: I changed it to an anonymous function during the test, in fact, you can implement // getValidateCode () as a separate function without doing so, and execute the function at $ (function () {// Click the button, that is, the above blue code;}); script
 

Here is just a small example. In practice, you may need to record various times. Considering the changes in page refresh, you need to use cookies to store data!

I hope this article will help you design javascript programs.

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.