js限制button十秒内不能重复点击

#编程技术 2019-10-29 16:46:00 | 全文 109 字,阅读约需 1 分钟 | 加载中... 次浏览

👋 相关阅读


js限制button十秒内不能重复点击

<html>
<body>
<input type="button" value="按钮" id="btn"/>
</body>
<script>
var wait = 10;
    document.getElementById("btn").onclick = function() {
        time(this);
        alert("十秒后解除点击限制!");
    }
    function time(o) {
        if (wait == 0) {
            o.removeAttribute("disabled");
            wait = 10;
        } else {
            o.setAttribute("disabled", true);
            wait--;
            setTimeout(function() {
                time(o)
            }, 1000)
        }
    }
</script>
</html>
Edit | Last updated on 2024-03-04 23:34:50




×