我有这个代码:
$('.selector').on({
touchstart: function (e) {
e.preventDefault();
alert(3);
e.stopPropagation();
},
tap: function (e) {
e.preventDefault();
alert(4);
e.stopPropagation();
}
});
仅触发 touchstart。谁能解释为什么?
PS:这就是我包含 jQuery mobile 脚本的方式:
<script src="http://code.jquery.com/mobile/1.4.4/jquery.mobile-1.4.4.min.js"></script>
编辑:我想在我的一个 div 上引入悬停功能,我认为使用点击事件就像单击和使用 touchstart 一样悬停。
$('.selector').on('tap swipe', function (e) {
e.preventDefault();
if(e.type == 'swipe') {
alert(1);
}
if(e.type == 'tap') {
alert(2);
}
e.stopPropagation();
});
$('.selector .sel1').on('tap swipe', function (e) {
e.preventDefault();
if(e.type == 'swipe') {
alert(3);
}
if(e.type == 'tap') {
alert(4);
}
e.stopPropagation();
});
使用此代码,我的 div 上的滑动事件可以正常工作,但对于内部元素,我无法重现滑动事件,只有点击被触发。我真的想不通为什么。