为什么“onmouseover”会出现? 事件使用“返回真” 防止默认行为?
我已经搜索这个有一段时间了,但没有得到任何解释。
对于 JavaScript 中的“onclick”和其他事件,返回 false 的事件处理程序意味着“阻止默认操作”。 然而,“onmouseover”有一个例外。 对于“onmouseover”,返回true表示“阻止默认操作”。
为什么“onmouseover”会有如此奇怪的例外情况?
I have been searching for this for some time, but haven't got any explanation.
For "onclick" and other events in javascript, the event handler returning false means "prevent default action". However, there is one exception for "onmouseover". For "onmouseover", returning true means "prevent default action".
Why is there such a weird exceptional case for "onmouseover"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不要使用 return false / true 来阻止默认事件行为,而是在事件对象上使用默认方法/属性:
Instead of using return false / true to prevent default event behaviour, use the default method / attribute on the event object:
据我所知,返回
true
以防止链接的 url 显示在状态栏中是 IE 特定的(错误)功能。 试图理解 IE 为何这样做通常是徒劳的 - 只能接受它......As far as I know, returning
true
to prevent the url of a link to show up in the status bar is an IE-specific (mis-)feature. And trying to understand why IE does things the way it does is often a lost cause - just live with it...谁知道真正的原因。 就是这样:
你从 onmouseover 返回 TRUE 以防止 url 出现在状态栏中,这确实是默认行为。
Who knows why really. Just the way it is:
you return TRUE from onmouseover to prevent url from appearing in the status bar, which would be the default behaviour indeed.