且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

计算Javascript中两次点击之间的时间

更新时间:2023-02-05 21:10:37

这样的东西会做的伎俩。保留变量与最后一次点击的时间,然后在用户再次单击链接时进行比较。如果差异

Something like this would do the trick. Keep a variable with the time of the last click and then compare it when the user clicks the link again. If the difference is < 5 seconds show the alert

<a id='testLink' href="#">click here</a>
<script type='text/javascript'>
    var lastClick = 0;
    $("#testLink").click(function() {
        var d = new Date();
        var t = d.getTime();
        if(t - lastClick < 5000) {
             alert("LESS THAN 5 SECONDS!!!");
        }
        lastClick = t;
    });
</script>