js,jquery发送短信倒计时实现代码
2018-07-20 来源:open-open
js:
<input type="button" id="btn" value="免费获取验证码" />
<script type="text/javascript">
var wait=60;
function time(o) {
if (wait == 0) {
o.removeAttribute("disabled");
o.value="免费获取验证码";
wait = 60;
} else { // www.jbxue.com
o.setAttribute("disabled", true);
o.value="重新发送(" + wait + ")";
wait--;
setTimeout(function() {
time(o)
},
1000)
}
}
document.getElementById("btn").onclick=function(){time(this);}
</script>
jq:(js的那个在我的项目上不是很好用自己写了一个jq的)
var step = 59;
$('#btn').val('重新发送60');
var _res = setInterval(function()
{
$("#btn").attr("disabled", true);//设置disabled属性
$('#btn').val('重新发送'+step);
step-=1;
if(step <= 0){
$("#btn").removeAttr("disabled"); //移除disabled属性
$('#btn').val('获取验证码');
clearInterval(_res);//清除setInterval
}
},1000);
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
最新资讯
热门推荐