<script>
var myButton = document.getElementById("myButton");
var clickCount = 0;
var timer;
myButton.addEventListener("click", function() {
clickCount++;
timer = setTimeout(function() {
if (clickCount === 1) {
// 执行单击事件的操作
console.log("单击事件触发");
}
clickCount = 0;
}, 300);
});
myButton.addEventListener("dblclick", function() {
clearTimeout(timer);
// 执行双击事件的操作
console.log("双击事件触发");
clickCount = 0;
});
</script>
预格式化文本将缩进 4 格
Click and Double Click Event
点击或双击我
1赞