请有人帮我解决这个问题:
touchStart = function (evt) {
evt.preventDefault();
$(this).addClass("touched");
};
touchEnd = function (evt) {
evt.preventDefault();
$(this).removeClass("touched");
};
s.ontouchstart = touchStart;
s.ontouchend = touchEnd;
s.ontouchmove = touchEnd;
我有一个 section 元素,由 JavaScript 动态生成 (ul > li > section)。当我将 touchstart-touchmove-touchend 事件监听器绑定(bind)到此部分元素时,它适用于 Android,但不适用于 iPad/iPod/iPhone。
我已经尝试使用 onclick="void(0)"
属性生成它,它使 section 元素像可点击元素一样“交互”,但它仍然什么都不做。
它在 Android 上的所有方面都适用,但这种蔬菜现在对我来说似乎有点消耗无用... =)
提前致谢! =)
最佳答案
没关系,用 jQuery 搞定了。这样它就可以到处运行。
$(s).bind("touchstart mousedown", function (e) {
console.log(e.type); // to get the name of the event
}).bind("touchmove mousemove", function (e) {
// ...
}).bind("touchend mouseup", function (e) {
// ...
});
关于javascript - HTML5 部分 touchstart touchmove touchend iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10834222/