<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
button {
margin: 0 0 0 3px;
}
</style>
</head>
<body>
手机号码:<input type="tel" maxlength="11"><button>发送</button>
<script>
var ipt = document.querySelector('.number');
var btn = document.querySelector('button');
var time = 10; //定义剩下的描述
btn.addEventListener('click', function() {
btn.disabled = true;
var timer = setInterval(function() {
if (time == 0) {
//清除定时器和复原按钮
clearInterval(timer);
btn.disabled = false;
btn.innerHTML = '再次发送';
time = 10; //倒计时从新开始
} else {
btn.innerHTML = '还剩下' + time + '秒';
time--;
}
}, 1000)
})
</script>
</body>
</html>