移動端禁止點擊一次,執行屢次事件問題

//防止觸發兩次
var t1 = null;//這個設置爲全局
function myclick(fn){
    if (t1 == null){
        t1 = new Date().getTime();
    }else{       
        var t2 = new Date().getTime();
        if(t2 - t1 < 500){
            t1 = t2;
            return;
        }else{
            t1 = t2;
        }
    }
    if (fn) {
        fn();
    }
}

也可:spa

btn.off().on('tap',{
   ....     
})

看狀況。。。。3d

相關文章
相關標籤/搜索