以下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!');
}
});
});
你在使用触摸屏吗?如果是这样,你可能需要使用'touchstart'和'touchend'
或者使用touchstart
,touchleave
和touchend
$(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!');
}
});
});