使用“触摸结束”检测长时间触摸的问题是,如果您希望事件在一定时间后触发,则它将无法正常工作。最好在触摸开始时使用计时器,并在触摸结束时清除事件计时器。可以使用以下模式:
var onlongtouch; var timer;var touchduration = 500; //length of time we want the user to touch before we do somethingtouchstart() { timer = setTimeout(onlongtouch, touchduration); }touchend() { //stops short touches from firing the event if (timer) clearTimeout(timer); // clearTimeout, not cleartimeout..}onlongtouch = function() { //do something };


