Js:
<input type= "button" id= "btn" value= "Get Verification Code free"/>
<script type= "Text/javascript" >
var wait=60;
function Time (o) {
if (wait = = 0) {
O.removeattribute ("Disabled");
O.value= "Free access to verification code";
wait = 60;
} else {//www.jbxue.com
O.setattribute ("Disabled", true);
O.value= "Resend (" + Wait + ")";
wait--;
SetTimeout (function () {
Time (O)
},
1000)
}
}
document.getElementById ("Btn"). Onclick=function () {time (this);}
</script>
JQ: (JS's that on my project is not very useful to write a JQ)
var step = 59;
$ (' #btn '). Val (' Resend 60 ');
var _res = setinterval (function ()
{
$ ("#btn"). attr ("Disabled", true);//Set disabled property
$ (' #btn '). Val (' Resend ' +step);
Step-=1;
if (step <= 0) {
$ ("#btn"). Removeattr ("Disabled"); Remove Disabled property
$ (' #btn '). Val (' Get Verification Code ');
Clearinterval (_res);//Clear SetInterval
}
},1000);
Transfer from http://blog.csdn.net/yanfangphp/article/details/21469755
JS,JQ Send SMS Countdown