手机端js模拟长按事件(代码仿照jQuery)

代码编写:javascript

$.fn.longPress = function(fn) {
	var timeout = undefined;
	var $this = this;
	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);
	}
}

代码使用:java

$(select).longPress(function(){
	alert(1);
});
相关文章
相关标签/搜索