onTouchEnd not working for Android Froyo 2.2?
The following html when opened in the default browser on Android 2.2 registers touchstart and touchmove events properly, but not touchend events. Any idea why?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0"/>
</head>
<body>
<div id="a" onTouchStart="touchstartFunction(event);"
onTouchMove="touchmoveFunction(event);"
onTouchEnd="touchendFunction(event);"
style="width:300px ; height:300px;background:red;"></div>
<script>
function touchstartFunction(event){
event.preventDefault();
var touch = event.touches[0];
document.getElementById('touchMoveTextbox').value = "Touch start at " + touch.pageX + "x" + touch.pageY;
}
function touchmoveFunction(event){
event.preventDefault();
var touch = event.touches[0];
document.getElementById('touchMoveTextbox').value = "Touch move at " + touch.pageX + "x" + touch.pageY;
}
function touchendFunction(event){
event.preventDefault();
var touch = eve开发者_如何学编程nt.touches[0];
document.getElementById('touchMoveTextbox').value = "Touch end at " + touch.pageX + "x" + touch.pageY;
}
</script>
<input type='textbox' size="30" id='touchMoveTextbox' >
</body>
</html>
Believe you might be experiencing this: touchend event doesn't work on Android
because you access touches[0] which is empty in the last case and causing a javascript error.
精彩评论