鼠标连续点击三次事件怎么实现啊?我觉得应该用setTimeout和计数器变量来写,但想了好久还是没想出思路来,不知道怎么弄出来,求解啊

解决方案 »

  1.   

    用一个变量var i =0;
    单击一次加1
    等于3时,发生事件,再i = 0;
      

  2.   

    先来个 双击的
    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();
    };
    关于上面的写法,参考 javascript 解释器模式: http://www.uml.org.cn/sjms/200805214.asp看懂双击再看三击就简单了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();
    };四击之类也很容易扩展
      

  3.   

    写错,三击的定义是
    function ClickState(sgl, dbl, tpl) {
      

  4.   

    每击一次,改变一下变量,根据变量decide!!!
      

  5.   

    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');
    }
    }
      

  6.   

    上面少复制了一行。。 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');
    }
    }
      

  7.   

    好吧,上面的又写错了。。 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');
    }
      

  8.   

    写着玩儿,LZ可以试试
    <!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>
      

  9.   

    写程序不能太实际了你们要看清楚
    大于 1击的 就代表 N击事件(N表示一个 >1的整数)剩下的去实现吧