How to bind 'touchstart' and 'click' events but not respond to both?

前端 未结 30 3059
抹茶落季
抹茶落季 2020-11-22 14:08

I\'m working on a mobile web site that has to work on a variety of devices. The one\'s giving me a headache at the moment are BlackBerry.

We need to support both key

30条回答
  •  伪装坚强ぢ
    2020-11-22 14:30

    Being for me the best answer the one given by Mottie, I'm just trying to do his code more reusable, so this is my contribution:

    bindBtn ("#loginbutton",loginAction);
    
    function bindBtn(element,action){
    
    var flag = false;
    $(element).bind('touchstart click', function(e) {
        e.preventDefault();
        if (!flag) {
            flag = true;
            setTimeout(function() {
                flag = false;
            }, 100);
            // do something
            action();
        }
        return false;
    });
    

提交回复
热议问题