2

シンプルな HTML ページで使用する場合は正常に動作する longpress イベントを処理するために Javascript を使用していますが、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.");
    }
  });
});
4

2 に答える 2

1

touchstarttouchendイベントを使用してみてください

そう:

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

$('#Button1').on('touchend', function() {
    //Logic
});
于 2012-11-19T06:20:16.013 に答える