87,989
社区成员
发帖
与我相关
我的任务
分享
var count = 0, timer;
document.onclick = function(){
if(count < 2){
if(timer){
clearTimeout(timer);
}
count ++;
timer = setTimeout(function(){
count = 0;
}, 500);
}else if(count === 2){
count = 0;
clearTimeout(timer);
threeClick();
}
}
function threeClick(){
alert('three click');
} var count = 0, timer;
document.onclick = function(){
if(count < 3){
if(timer){
clearTimeout(timer);
}
count ++;
timer = setTimeout(function(){
count = 0;
}, 500);
}else if(count = 3){
count = 0;
alert('three click');
}
} document.onclick = function(){
if(count < 3){
if(timer){
clearTimeout(timer);
}
count ++;
timer = setTimeout(function(){
count = 0;
}, 500);
}else if(count = 3){
count = 0;
alert('three click');
}
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
</script>
<style type="text/css">
</style>
</head>
<body>
<input type="text" id='a' onclick='' value='三点。。。'/>
<div style="height:1000px;width:400px;">sdf</div>
<script type="text/javascript">
function ck(n, fn) {
this.fn = fn;
this.size = n;
this.index = 0;
this.flag = false;
this.id = null;
}
ck.prototype = {
action: function() {
this.flag = true;
this.index++;
if(this.index === this.size) {
this.reset();
s = [];
Array.prototype.push.apply(s, arguments);
this.fn.apply(s.shift(), s);
} else {
this.id = setTimeout((function(o, n) {
return function() {
o.time(n);
}
})(this, this.index), 200);
}
},
time: function(n) {
if(n >= this.index) {
this.reset();
}
},
reset: function() {
this.flag = false;
this.index = 0;
clearTimeout(this.id);
}
};
var cl = new ck(3, function(e, str) {
alert(this.value);
alert(e.button);
alert(str);
});
document.getElementById('a').onclick = function(e){
cl.action(this, e, 'dddd')
};
</script>
</body>
</html>
function ClickState(sgl, dbl) {
var me = this,
state = null,
timer0 = null;
function s0() {
timer0 = setTimeout(function() {
state = s0;
sgl();
}, 200);
state = s1;
}
function s1() {
clearTimeout(timer0);
state = s0;
dbl();
}
state = s0;
this.next = function() {
state();
};
}
function sgl() {console.info('single');}
function dbl() {console.info('double');}
state = new ClickState(sgl, dbl);
document.onclick = function() {
state.next();
};
function ClickState(sgl, dbl) {
var me = this,
delay = 200,
state = null,
timer = null;
function s0() {
timer = setTimeout(function() {
state = s0;
sgl();
}, delay);
state = s1;
}
function s1() {
clearTimeout(timer);
timer = setTimeout(function() {
state = s0;
dbl();
}, delay);
state = s2;
}
function s2() {
clearTimeout(timer);
timer = setTimeout(function() {
state = s0;
tpl();
}, 200);
state = s2;
}
state = s0;
this.next = function() {
state();
};
}
function sgl() {console.info('single');}
function dbl() {console.info('double');}
function tpl() {console.info('triple');}
state = new ClickState(sgl, dbl, tpl);
document.onclick = function() {
state.next();
};