jquery 倒计时60秒! 直接复制代码就可以

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no" id="viewport" name="viewport">
<title>60s倒计时</title>
<script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script>
</head>
<body>
<input type="button" id="btn" value="免费获取验证码" />
<script type="text/javascript">
//发送验证码按钮的60s倒计时

var countdown = 60;
$('#btn').css('background','#0af');
$('#btn').css('border','none');
$('#btn').css('borderRadius','5px');
$('#btn').css('height','30px');
$('#btn').css('color','#fff');

function sendemail(obj) {
// var obj = $("#btn");
settime(obj);
}

function settime(obj) {
if (countdown == 0) {
obj.attr('disabled', false);
obj.val("免费获取验证码");
countdown = 60;
return;
} else {
obj.attr('disabled', true);
obj.val("重新发送(" + countdown + ")");
countdown--;
$('#btn').css('background', '#999')
}
setTimeout(function() {
settime(obj)
}, 1000)
}


$('#btn').click(function() {
settime($('#btn'))
})
</script>
</body>
</html>
posted @ 2018-07-26 14:09  小猴子会上树  阅读(254)  评论(0编辑  收藏  举报