<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<input type="button" style="height:32px;width:120px;" value="点击发送验证码" οnclick="sendCode(this)" />
<script type="text/javascript">
var clock = '';
var nums = 60;
var btn;
function sendCode(thisBtn)
{
btn = thisBtn;
btn.disabled = true; //将按钮置为不可点击
btn.value = nums+'秒后可重新获取';
clock = setInterval(doLoop, 1000); //一秒执行一次
}
function doLoop()
{
nums--;
if(nums > 0){
btn.value = nums+'秒后可重新获取';
}else{
clearInterval(clock); //清除js定时器
btn.disabled = false;
btn.value = '点击发送验证码';
nums = 60; //重置时间
}
}
</script>
</body>
</html>
转载于:https://my.oschina.net/dxpinfo/blog/818939