为什么"onmouseover"事件使用"return true"来防止默认行为?

Mor*_*eng 7 javascript events onmouseover event-handling

我一直在寻找这个,但没有得到任何解释.

对于"onclick"和javascript中的其他事件,返回false的事件处理程序意味着"防止默认操作".但是,"onmouseover"有一个例外.对于"onmouseover",返回true表示"防止默认操作".

为什么"onmouseover"有这么奇怪的例外情况?

Luc*_*eis 6

不使用return false/true来防止默认事件行为,而是使用事件对象上的默认方法/属性:

elem.onmouseover = function(e) {
    if (!e) var e = window.event; // IE
    if(e.preventDefault) {
        e.preventDefault();
    } else {
        e.returnValue = false; // IE
    }
}
Run Code Online (Sandbox Code Playgroud)