Firefox DOM2 鼠标按下事件在使用 stopPropagation 时选择元素
我有一个链接元素,可以在其中捕获 mousedown 事件并阻止该事件冒泡,以便页面中的其他元素不会被选择。 然而,在 Firefox(3 和 3.5)中,当我使用 DOM 2 事件模型时,它仍然选择页面中的其他元素。
我已经在歌剧中对其进行了测试,并且无需选择其他元素即可正常工作。 另外一个奇怪的问题是,如果我使用 DOM 0 事件模型,它可以正常工作并且不会选择其他元素。 这是 Firefox 的错误还是我做错了?
这是我用来测试的 2 个事件处理程序
past.addEventListener('mousedown', function (e) {
e.stopPropagation();
return false;
}, false);
past.onmousedown = function (e) {
e.stopPropagation();
return false;
};
I have a link element where I capture the mousedown event and stop the event from bubbling so that other elements in the page don't get selected. However in firefox (3 & 3.5) when i use the DOM 2 event model It still selects other elements in the page.
I have tested it in opera and it works fine without selecting other elements. Also another weird issue is that if I use the DOM 0 event model it works fine and doesn't select other elements. Is this a bug in firefox or am I just doing it wrong?
Here are the 2 event handlers I used to test
past.addEventListener('mousedown', function (e) {
e.stopPropagation();
return false;
}, false);
past.onmousedown = function (e) {
e.stopPropagation();
return false;
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您尝试过
e.preventDefault()
吗?stopPropagation
将停止调用祖先元素上的事件处理程序,但这与阻止执行默认操作不同。 由于 DOM 规范并没有真正指定鼠标事件和选择应该如何根据事件模型进行交互,因此它可能是一个浏览器以一种方式执行,另一个以另一种方式执行的区域之一,而且两者都不是“正确”或“正确”的。 “错误的”。Have you tried
e.preventDefault()
?stopPropagation
will stop the event handlers on ancestor elements being invoked, but this is not the same thing as preventing the default action from being taken. As the DOM specs don't really specify how mouse events and selection should interact in terms of the event model, it may be one of those areas where one browser does it one way, one does it another, and neither is "right" or "wrong".