我在js中修改touchevents
。我在eclipse中的logcat中遇到了这个错误。Uncaught TypeError:无法读取属性'pageX'的undefined
document.getElementById("squareBracket").
addEventListener("touchmove", touchHandler, false);
document.getElementById("squareBracket").
addEventListener("touchend", touchHandler, false);
function touchHandler(e) {
if (e.type == "touchstart") {
alert("You touched the screen!");
} else if (e.type == "touchmove") {
// alert(e.changedTouches[0].pageX);
// alert(e.changedTouches[0].pageY);
} else if (e.type == "touchend" || e.type == "touchcancel") {
alert('X :' + e.targetTouches[0].pageX);
alert('Y :' + e.targetTouches[0].pageY);
}
}
如果我删除在if
评论中touchmove
,坐标弹出。但是,如果它被评论,我的logcat中的错误出现。
首先,评论不会影响你的logcat错误。看来e.targetTouches [0]为空或未定义。请注意它在第一种情况下是“changedTouches”,在第二种情况下是“targetTouches”。 – cosmincalistru
所以我应该把它改成'changedtouches'? – Jeongbebs