我正在一个移动网站上工作,并且在我不希望它们触发的事件中挣扎。
为了简单起见,它是这样写的(在 jQuery 中):
el.on('touchend', function(ev) {
ev.preventDefault();
// fire an ajax call
};
但是,有时用户会在滚动页面时点击该项目,从而触发 ajax 请求(从而改变页面状态)。
我想不出办法(ev.stopPropagation()
没用),所以我决定关注dragstart
事件dragend
。
el.on('dragstart', function() {
el.off('touchend');
});
el.on('dragend', function(ev) {
ev.stopPropagation(); // <-- seems to do nothing
// add back the event above (the function is set to a var)
});
如果我在touchend
回调中发出警报,我会确认touchend
在我停止拖动后事件确实触发了。
有谁知道如何防止任何其他事件触发?我希望我只是失明并且错过了一些明显的东西。