Click and double-click event firing

后端 未结 3 1334
长情又很酷
长情又很酷 2021-01-22 01:35

I\'m writing event handlers using jQuery, and had a question about the click and double-click events. I\'ve got an element with a class \"file\" on it. It has two event handlers

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-22 02:27

    As James mentions in his comment, there cannot be one without the other. It's going to be a bit of a hack, but you can have these work independently with a timer:

    $('.file').live('dblclick', function() {
    
    
      $(this).data('doubleClicked', true);
      //event handler code
    
    });
    
    function SingleClickHandle(this)
    {
      if (! $(this).data('doubleClicked'))
      {
      //event handler code
      }
    }
    
    $('.file').live('click', function(){
    
      $(this).data('doubleClicked', false);
      setTimeout('SingleClickHandler(this)', 500); // is half a second enough to consider it a double-click?
    
    });
    

提交回复
热议问题