0

我正在做一个phonegap项目。我需要实现一个长按事件。我们如何使用 JavaScript 检测长按图像/按钮?

4

2 回答 2

2
$('#target').mousedown(function() {
  alert('Handler for .mousedown() called.');
  //start a timer
});

$('#target').mouseup(function() {
  alert('Handler for .mouseup() called.');
  //stop the timer and decide on long click

});
于 2012-07-09T09:22:33.383 回答
1

我想到的一种方法是:

  1. 在 onclick 事件的开始,记录时间,这给你第一次点击的时间。

  2. 然后检查时间跨度。假设,您说 5 秒的时间跨度是长按事件。如果检查成功,这是一个长按事件。

于 2012-07-09T09:21:52.907 回答