Js countdown button instance and js countdown instance
This example describes 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:
<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 ("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> </span>
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.