長按鈕觸發事件的方法

這裏是代碼的邏輯編寫部分javascript

$.fn.longPress = function(fn) {
	    var timeout = undefined;
	    var $this = this;
	    alert(this.length);
	    for(var i = 0;i<$this.length;i++){
	        $this[i].addEventListener('touchstart', function(event) {
	            timeout = setTimeout(fn, 800);
	            }, false);
	        $this[i].addEventListener('touchend', function(event) {
	            clearTimeout(timeout);
	            }, false);
	    }
	    }
  

代碼的代用部分,其中select是你所要獲取的元素java

  $(select).longPress(function(index){
    	alert("你已長按");
	});
相關文章
相關標籤/搜索