js 處理同時綁定單擊和雙擊的方法

原理:點擊事件延遲執行,雙擊觸發時,取消本該執行單擊事件的定時器this

var timeout =null;   

$("#Btn").on("click",function(){

      clearTimeout(timeout);//中止單擊定時事件

      timeout= window.setTimeout(function(){//延遲單擊事件觸發內容               

       console.log("this is click event");                     

       }, 200);             });          

$("#Btn").on("dblclick",function(){               

    clearTimeout(timeout);  //中止單擊定時事件

     console.log("this is dblclick event");                     

   });
相關文章
相關標籤/搜索