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.