我正在使用phonegap,需要使用'touchstart'加快點擊響應,只有意識到沒有'touchstart','touchmove', 'touchend'正在射擊,但'點擊'。觸摸事件不工作在Android手機網絡視圖(甚至內置的瀏覽器)
我甚至在測試內置的瀏覽器(7" 的Android 4.0.3平板電腦)一個簡單的頁面,並發現它失敗了。
我兩片測試還是一樣。 在以下頁面, BUTTON2只顯示「html_click」,BUTTON3只顯示「點擊」:
<!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
朋友告訴你的概念顯然 –
我要添加傾聽'touchstart',並且它不會被解僱。我應該怎麼做才能使它工作? –
我覺得你需要在html文件本身創建那個觸摸監聽器更好 –