阻止按钮快速点击

<!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>

 

posted @ 2018-07-13 16:21  井凉一一  阅读(175)  评论(0编辑  收藏  举报