jq获取验证码倒计时60s

1.html部分

<input type="button" id="zh_get" value="获取验证码" />

2.js部分(需要引入jq)

var countdown=10;
$("#zh_get").on("click",function(){
	settime($(this));
});
//计时器函数
function settime(obj) {
	if(countdown <= 0) {
		obj.attr("disabled",false);
		obj.val("免费获取验证码");
		countdown = 60;
		return;
        } else {
		obj.attr("disabled",true);
		obj.val("重新发送(" + countdown + ")");
		countdown--;
	}
	setTimeout(function() {
		settime(obj)
	}, 1000)
}

猜你喜欢

转载自blog.csdn.net/hangge0111/article/details/80828630