2016-08-25 25 views
0

我使用jquery doubletap函數來檢測android和IOS上的doubleclicks。這個選擇器不能用於雙重插件

(function($){ 
// Determine if we on iPhone or iPad 
var isiOS = false; 
var agent = navigator.userAgent.toLowerCase(); 
if(agent.indexOf('iphone') >= 0 || agent.indexOf('ipad') >= 0){ 
     isiOS = true; 
} 

$.fn.doubletap = function(onDoubleTapCallback, onTapCallback, delay){ 
    var eventName, action; 
    delay = delay == null? 500 : delay; 
    eventName = isiOS == true? 'touchend' : 'click'; 

    $(this).bind(eventName, function(event){ 
     var now = new Date().getTime(); 
     var lastTouch = $(this).data('lastTouch') || now + 1 /** the first time this will make delta a negative number */; 
     var delta = now - lastTouch; 
     clearTimeout(action); 
     if(delta<500 && delta>0){ 
      if(onDoubleTapCallback != null && typeof onDoubleTapCallback == 'function'){ 
       onDoubleTapCallback(event); 
      } 
     }else{ 
      $(this).data('lastTouch', now); 
      action = setTimeout(function(evt){ 
       if(onTapCallback != null && typeof onTapCallback == 'function'){ 
        onTapCallback(evt); 
       } 
       clearTimeout(action); // clear the timeout 
      }, delay, [event]); 
     } 
     $(this).data('lastTouch', now); 
    }); 
}; 
})(jQuery); 

然後,根據手機是/否,我使用此代碼來觸發事件。

if(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) { 

     $('#table1 tbody tr').doubletap(function() { 

      var href = $(this).attr("relationid"); 
      alert(this); 
      if (href) { 
       window.location = 'details/?id=' + href; 
      } 
     }); 
    }else{ 
     $('#table1 tbody tr').click(function() { 
      var href = $(this).attr("relationid"); 
      if (href) { 
       window.location = 'details/?id=' + href; 
      } 
     }); 
    } 

甲錶行看起來像這樣:

<tr class="test odd" relationid="1" role="row"> 
    <td>1</td> 
    <td class="sorting_1">Testklant</td> 
    <td>90.00</td> 
</tr> 

的問題是,使用doubletap()時,未選擇relationid屬性。它使用click()可以正常工作。

當我提醒var href時,它會顯示「[object Window]」。

如何解決?

+0

我發現了jquerymobile的這些錯誤。這就是爲什麼我的解決方案是,不要使用jQuery的手機,只使用jQuery的就夠了。 –

+0

切換到手指插件。現在效果很好。 http://ngryman.sh/jquery.finger/ – Mbrouwer88

回答

相關問題