[英]touch events not working in android phonegap webview (or even built-in browser)
我使用的是phonegap,需要使用“ touchstart”来加快点击响应,只是意识到“ touchstart”,“ touchmove”,“ touchend”没有触发,而是“ click”触发。
我什至在内置浏览器(7英寸android 4.0.3平板电脑)中测试了一个简单的页面,但发现它失败了。
我测试了两种平板电脑,它们仍然相同。 在下一页中,button2仅显示“ html_click”,button3仅显示“ click”:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf8">
<meta name="viewport" content="target-densitydpi=device-dpi, width=device-width">
<title>Droid touch event test.</title>
</head>
<body>
<button id="button">touch it</button>
<button id="button2" ontouchstart="d_('html_touchstart')" onclick="d_('html_click')">html</button>
<button id="button3">touch 3</button>
<div id="db"></div>
<script>
function $(d){return document.getElementById(d)}
function d_(m){dbo.innerHTML=dbo.innerHTML+' '+m}
function ts1(e){d_('document touched')}
function ts2(e){d_('button touched')}
function eh(e){
d_(e.type);
}
var ets='touchstart',dbo=$('db');
document.addEventListener(ets,ts1,false);
$('button').addEventListener(ets,ts2,false);
$('button3').addEventListener(ets,eh,false);
$('button3').addEventListener('touchend',eh,false);
$('button3').addEventListener('click',eh,false);
</script>
</body>
</html>
为什么'touchstart不触发? 我应该做些什么使触摸事件起作用吗? 还是有其他方法可以使点击响应更快?
我使用了mousedown
事件,但效果很快。
mousedown
和click
之间的(new Date()).getTime()
差异(包括一些innerHTML
更改)仅约15。
我只保留了向您展示概念所需的内容,因此编写了该代码,并在ICS设备上使用Phonegap Build(默认为Phonegap 2.0,但没有关系)进行了测试。 应该为您工作:
<!DOCTYPE html>
<html>
<body>
<button id="button1">1</button>
<button id="button2">2</button>
<script>
document.getElementById("button1").addEventListener('touchstart',button1Pressed);
document.getElementById("button2").addEventListener('touchstart',button2Pressed);
function button1Pressed ()
{
alert('Button 1 Pressed');
}
function button2Pressed ()
{
alert('Button 2 Pressed');
}
</script>
</body>
</html>
我也面临同样的问题。 在下面的第一行中,我收到错误消息“ Android WebView和NO_FAST_DRAW = false”。 之后换到第二行。 有效。 错误发生在createCustomAlert('wpt')。 因此,我所谓的函数看起来像一个字符串。 这个错误来了。 所以请在功能调用处检查
onclick ='createCustomAlert('wpt')'
onclick ='createCustomAlert(3)'
我也遇到了同样的问题,将近三天时间把它弄乱了。 我在HTML输入标签(EditText)
上放置了点击事件,并尝试了一下,但是也没有用。 最后,奇迹般的是,我只用了一个简单的alert("Hello")
即可通过ontouchstart
进行查看。 令我惊讶的是,我成功尝试了近一个星期的警报和软键盘。 您也可以尝试一下。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.