如何避免在短时间内按钮被多次重复点击

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="jquery-3.3.1.min.js"></script>
    <script>
        $(document).ready(function(){
            var isClick = true;
            $("button").on("click",function(){
                // alert("hello");
                if(isClick) {
                    isClick = false;
                    /*点击后要执行的事件*/
                    console.log($(this).attr("data-val"));
                    /*设置1s之后点击才能执行事件*/
                    setTimeout(function() {
                        isClick = true;
                    }, 1000);
                }
            });
        });
    </script>
</head>
<body>
    <button id="btn1" data-val="111">按钮</button>
</body>
</html>

转载自:https://blog.csdn.net/weixin_40687883/article/details/81386127

原文地址:https://www.cnblogs.com/foreverlin/p/10124313.html