所有,我堅持處理嵌套元素懸停處理程序的問題。看來當鼠標輸入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