<!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset="UTF-8"> <title>Title</title> <style> div { width: 300px; height: 100px; margin: 100px auto; } </style> </head> <body> <div> <input type="text"> <button>发送</button> <script> var input = document.querySelector('input'); var btn = document.querySelector('button'); var time = 10; btn.onclick = function () { btn.disabled = true; // 禁用 按钮 var timer = setInterval(f, 1000); // 计时器 function f() { btn.innerHTML = '还剩' + time + 's可继续发送'; //更改按钮显示 time--; if (time < 0) { clearInterval(timer); // 结束 计时 btn.disabled = false; // 解禁 按钮 btn.innerHTML = '发送'; // 恢复 按钮内容 time = 10; // 重置倒计时时间 } } } </script> </div> </body> </html>