div onmouseout无法按预期工作 [英] div onmouseout does not work as expected
问题描述
文字和示例代码改编自 http:// www。 webdeveloper.com/forum/archive/index.php/t-65078.html ,可能无法反映实际问题:
Text and sample code adapted from http://www.webdeveloper.com/forum/archive/index.php/t-65078.html, may not reflect actual question:
我有一个div然后是div里面有一个嵌套表:父div之外还有一些div。
I have a div and then a div with a nested table inside it: also there is some div outside the parent div.
<div onmousemove="move()" onmouseout="out()">
<div id="dvRep"> </div>
<table>
<tr><td>ITEM 1</td></tr>
<tr><td>ITEM 2</td></tr>
<tr><td>ITEM 3</td></tr>
<tr><td>ITEM 4</td></tr>
<tr><td>ITEM 5</td></tr>
</table>
</div>
<div id="divChartPopupMenu">
Hide me.
</div>
每当我在div中移动鼠标时,它都会正确调用移动功能,但 onmouseout
属性不像我想的那样工作。我认为只有将鼠标移离div时才会调用 out()
函数,但是 out()
out()。我希望只有当用户离开整个div时才会调用 out()
。任何想法?
Whenever i move my mouse within the div it correctly calls the move function, but the onmouseout
attribute doesn't work like i thought. i thought that the out()
function would only be called if you moved your mouse off the div, but out()
is called whenever i move off one of the table rows. so if my mouse is on a row and i move to the next row it calls out()
. i want out()
to be called only when the user moves off the entire div. any ideas?
我正在尝试的是我正在隐藏另一个div的功能。
What i am trying is on out function i am hiding another div.
推荐答案
我建议你阅读这篇关于javascript事件的3个阶段的文章。
http://www.quirksmode.org/js/events_order.html
i suggest you to read this article on 3 phases of javascript events.
http://www.quirksmode.org/js/events_order.html
在函数移出或移出时,你可以查看是否srcElement(IE)或目标(W3C)有一个名为dvRep的id ..
in the function move or out, you can check if the srcElement(IE) or target(W3C) has an id called dvRep..
它应该是这样的:
function out(event)
{
event.stopPropagation(); //cancel bubbling
ele = event.target || event.srcElement
if (ele.id === "dvRep"){
//your code
}
}
这篇关于div onmouseout无法按预期工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!