繁体   English   中英

longphone事件在使用Phonegap的Android中不起作用

[英]longpress event not working in Android using Phonegap

我正在使用Javascript处理longpress事件,该事件在简单的HTML页面上使用时可以正常工作,但是当我在Phonegap / Android中使用此代码时,它不起作用,下面给出了代码:

$(document).ready(function() {
  debugger;
  var mousedowntime;
  $('#Button1').mousedown(function() {
    var d = new Date();
    mousedowntime = d.getTime();
    //alert('Handler for .mousedown() called.');
    //start a timer
  });
  $('#Button1').mouseup(function() {
    // debugger;
    //alert('Handler for .mouseup() called.');
    //stop the timer and decide on long click
    var d = new Date();
    //alert("mousedowntime=" + mousedowntime);
    presstime = d.getTime() - mousedowntime;
    //alert("presstime=" + presstime);
    if (presstime > 999/*You can decide the time*/) {
      //Do_Action_Long_Press_Event();
      alert("Long pressed.");
    } else {
      //Do_Action_Click_Event();
      alert("Click.");
    }
  });
});

尝试使用touchstarttouchend事件

所以:

$('#Button1').on('touchstart',function() {
    //Logic
});

$('#Button1').on('touchend', function() {
    //Logic
});

这是SO答案中的逻辑。 我希望这是您正在寻找的东西。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM