<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>点击判断单击还是双击</title>
</head>
<body>
<p>点击判断单击还是双击</p>
<script>
let p = document.getElementsByTagName('p')[0]
var lastTapTimeFunc
var lastTapDiffTime = 0
const handClick = function () {
let _this = this;
let curT = new Date().getTime()
let lastT = _this.lastTapDiffTime;
_this.lastTapDiffTime = curT
let diff = curT - lastT
if (diff < 300) {
console.log("双击");
clearTimeout(_this.lastTapTimeFunc)
} else {
_this.lastTapTimeFunc = setTimeout(function () {
console.log("单鸡");
}, 300)
}
}
p.addEventListener('click', handClick)
</script>
</body>
</html>