js获取验证码倒计时效果

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>One</title>
</head>
<body>
<input type="button" id="btn" value="发送验证码" onclick="OneTime(this)"/>
<script>
var cunt = 60;
function OneTime(val) {
if (cunt == 0){
val.removeAttribute("disabled")
val.value = "发送验证码"
cunt = 60;
} else {
val.setAttribute("disabled",true)
val.value = "请重新发送( "+ cunt +" )";
cunt--;
setTimeout(function () {
OneTime(val)
},1000)
}
}
</script>
</body>
</html>
posted @ 2019-02-15 10:59  菜鸟、零零柒  阅读(81)  评论(0编辑  收藏  举报