案例分享:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
手机号码:<input type="text" /> <button>获取短信验证码</button>
<script type="text/javascript">
var btn = document.querySelector('button')
var i=10;
btn .addEventListener('click',function(){
btn.innerHTML = i+'s'
btn.disabled = true;
var time = setInterval(function(){
if(i!=0){
btn.innerHTML = --i+'s';
}
else{
clearInterval(time)
i=10;
btn.disabled = false;
btn.innerHTML = '获取短信验证码'
}
},1000)
})
</script>
</body>
</html>