怎样用javascript在网页上捕获连续三次单击事件呢?
我发现在网页上如果连续三次单击就会把整行文字选中。请问怎样捕获三次单击事件啊?
有这样的原生事件的吗?
smiling
9 years, 2 months ago
Answers
可以自己用timeout来模拟一个三击事件。代码如下
<body>
<input type="text" id="inputText">
</body>
addTrebleClickHandler(document.getElementById("inputText"),function(){
alert("treble click");
})
function addTrebleClickHandler(element,handler){
var running = false;
var count = 0;
element.addEventListener("click",function(e){
if(running){
if(count == 2){
running = false;
count = 0;
if(handler){
handler();
}
}else{
count++;
}
}else{
running = true;
count++;
setTimeout(function(){
count = 0;
running = false;
},1000);
}
});
}
黑猫即是正义
answered 9 years, 2 months ago