var wait = 5;
document.getElementById("btn").onclick = function() {
time(this);
}
function time(o) {
if (wait == 0) {
o.removeAttribute("disabled");
wait = 5;
} else {
o.setAttribute("disabled", true);
wait--;
setTimeout(function() {
time(o)
}, 1000)
}
}
实现点击按钮后,五秒内按钮不能再次点击,这样就可以防止在有网络延迟的情况下,多次发送请求