mouseup,鼠标在android webview中不起作用

问题描述 投票:2回答:2

以下jquery在我的android webview中不起作用。当长按跨度超过10秒时,需要将其重定向到特定的网址,这是在网站上工作但不能在android webview上工作。

$(function() {
  var longpress = 10000;
  var start;

  jQuery("#restart").on('mousedown', function(e) {
    start = new Date().getTime();
  });

  jQuery("#restart").on('mouseleave', function(e) {
    start = 0;
  });

  jQuery("#restart").on('mouseup', function(e) {
    if (new Date().getTime() >= (start + longpress)) {
      alert('long press!');
      $("#restart >a").attr("href", "http://siteurl/?key=gesture")
    } else {
      alert('short press!');
    }
  });
});
android-webview
2个回答
2
投票

你在使用触摸屏吗?如果是这样,你可能需要使用'touchstart'和'touchend'


0
投票

或者使用touchstarttouchleavetouchend

$(function() {
  var longpress = 10000;
  var start;

  jQuery("#restart").on('mousedown touchstart', function(e) {
    start = new Date().getTime();
  });

  jQuery("#restart").on('mouseleave touchleave', function(e) {
    start = 0;
  });

  jQuery("#restart").on('mouseup touchend', function(e) {
    if (new Date().getTime() >= (start + longpress)) {
      alert('long press!');
      $("#restart >a").attr("href", "http://siteurl/?key=gesture")
    } else {
      alert('short press!');
    }
  });
});
© www.soinside.com 2019 - 2024. All rights reserved.