<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <!--<script src="https://cdn.bootcss.com/jquery/3.2.0/jquery.min.js"></script>-->
    <title>单双击事件测试</title>
</head>
<body>
<button onclick="test()" ondblclick="dbclick()">测试</button>
</body>

<script>
    var timeId;
    function test() {
        clearTimeout(timeId);
        timeId = setTimeout(function () {
            console.log("单击");
        }, 250);
    }
    function dbclick() {
        clearTimeout(timeId);
        console.log("双击");
    }
</script>
</html>

junbaor
847 声望36 粉丝

广泛涉略,快速学习