2009-10-25 73 views
0

當你在元素「parent」上有一個mouseover觀察者,並且事件被「parent」的子元素「child」觸發時,event.element()返回子元素。 但是當你在元素上有一個mouseout觀察者,並且它從一個子元素被觸發時,event.element()只返回父元素。如何找到在JS Prototype中觸發mouseout事件的元素?

我真的需要知道mouseout事件是否被父母或孩子解僱了,我該怎麼做?

+1

事實上,' mouseout'就像'mouseover'一樣。即,兩者都可以源自「孩子」。請參閱http://www.quirksmode.org/dom/events/mouseover.html – 2009-10-25 21:48:22

+0

謝謝,這幫助了我 – albus 2009-10-25 22:18:44

回答

1

裏面的事件處理函數,你可以嘗試找回家長,如果你知道一些CSS選擇器適用於它或它的ID通過使用這樣的「向上」的方法:

function eventHandler(e) { 

    var parentElement; 

// I remember doing something like this, but not 100% its exactly what works 

    parentElement = e.element().up('some css selector to find parent') || e.element(); 

    // do whatever you want with parentElement 

} 
相關問題