解决单双击冲突

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <button>按钮</button>
    <script src="jquery.js"></script>
    <script>
        $(function () {
            var time =null;
            $("button").click(function () {
                clearTimeout(time);

                time = setTimeout(function () {
                    console.log("单机")

                },300);

            })

            $("button").dblclick(function () {

                clearTimeout(time);
                console.log("双击")

            });


        })
    </script>
</body>
</html>

猜你喜欢

转载自www.cnblogs.com/lxx7/p/9761204.html