所有,我坚持处理嵌套元素悬停处理程序的问题。看来当鼠标输入child
时,祖先也处于hover
状态,有没有什么办法触发hoverout
事件的祖先,当鼠标输入child
元素时?嵌套元素悬停句柄
下面是我试图做到目前为止。请检查它。
<style>
div
{
border:1px solid red;
margin:10px;
padding:10px;
}
</style>
<script>
$(function() {
$('div').each(function(){
var current = this;
$(this).hover(function(event){
event.stopPropagation();// doesn't work.
console.log('Capture for hover in ' + current.tagName + '#'+ current.id +
' target is ' + event.target.id); },
function(event){
event.stopPropagation();
console.log('Capture for hover out' + current.tagName + '#'+ current.id +
' target is ' + event.target.id); });
});
});
</script>
<body id="greatgrandpa">
<div id="grandpa">
<div id="parent">
<div id="child"/>
</div>
</div>
</body>
只需删除asterix并运行图像上的功能?您将循环中的事件处理程序附加到遍历页面上所有元素的循环中! – adeneo 2013-03-19 03:22:17
嗨,@ adeneo,我只是将问题更新清楚。请检查它。谢谢。 – 2013-03-19 03:30:40
我真的不明白,但是你可以将mouseenter/leave函数设置为任何你喜欢的东西,比如[** FIDDLE **](http://jsfiddle.net/FXU65/)?? – adeneo 2013-03-19 03:37:42