我有這樣的代碼:爲什麼點擊事件被touchstart事件抑制?
$('.selector').on({
touchstart: function (e) {
e.preventDefault();
alert(3);
e.stopPropagation();
},
tap: function (e) {
e.preventDefault();
alert(4);
e.stopPropagation();
}
});
只有touchstart被觸發。有人可以解釋爲什麼嗎?
P.S. :這是我包括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輕掃事件工作正常,但對於內部元件我無法重現刷卡事件,僅自來水被觸發。我真的不明白爲什麼。
即使我點擊我的div,第一個觸發的事件是touchstart,所以只會顯示警報3。我想分開touchstart和tap的行爲。 – 2014-10-06 09:32:59