js 双击会触发两次单击事件的解决方案
文章目录
<!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>
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论