阻止按钮快速点击

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>阻止按钮快速点击</title>
</head>
<body>


<button onclick="handel_text()">click me</button>
<script>
    var time_arr = [];
    function handel_text() {
        time_arr.unshift(Date.now());
        if (time_arr.length > 2) {
            time_arr.length = 2;
        }
        if (time_arr.length >= 2) {
            if (time_arr[0] - time_arr[1] < 1000) {
                return;
            }
        }
        yourFn();
    }

    function yourFn() {
        console.log('do success');
    }
</script>
</body>
</html>
原文地址:https://www.cnblogs.com/bagexiaowenti/p/9305662.html