JS implementation of the Countdown button instance _javascript skills

Source: Internet
Author: User

This article describes the JS implementation of the Countdown button. Share to everyone for your reference. The specific analysis is as follows:

The effect chart is as follows:

The specific code is as follows:

 <span style= "FONT-SIZE:14PX;" > <input type= "button" value= "OK" id= "Rulesubmit"/> <scripttypescripttype= "Text/javascript" > var secs = 
3; 
var wait = secs * 1000; 
var update = function (Num,value) {if (num = = wait/1000) {$ ("#rulesubmit"). Val ("Free access"); 
} else{Printnr = (wait/1000)-num; 
$ ("#rulesubmit"). Val ("Get Free (" + Printnr + ")"); 
} 
}; 
var timer = function () {$ ("#rulesubmit"). attr ("disabled", false); 
$ ("#rulesubmit"). Val ("Free access"); 
}; 
$ (function () {(function () {function Getvalidatecode () {$ ("#rulesubmit"). Val ("Get 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 (); 
});
})(); 
Notice that I'm here to change the anonymous function in the test, but I don't have to do this or implement//getvalidatecode () as a separate function, in the $ (function () {//click button to execute functions, that is, the blue portion of the code above;}); 
}); </script></span> 

Here is just a small example, in practical use, may need to record a variety of time, considering the page refresh changes, the need to use cookies for data storage and so on!

I hope this article will help you with your JavaScript programming.

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.