給每個鏈路ID和類。當鼠標進入您的某個特殊鏈接的活動區域時,使用鼠標懸停的鏈接的ID在所有鏈接上激發您的自定義事件。讓您的自定義事件處理程序檢查以確保該ID與收到事件通知的鏈接的ID不匹配。
<a class="fancy-hover" id="1" href="foo">Example Link 1</a>
<a class="fancy-hover" id="2" href="bar">Example Link 2</a>
<a class="fancy-hover" id="3" href="qux">Example Link 3</a>
<script type="text/javascript">
// custom event
$("a.fancy-hover").bind('mouseOverOneOfUs',function(event, whatMouseHoversOver){
// Prevent item mouse is over from responding.
if (whatMouseHoversOver != this.id) {
// do something
}
return false; // Stop propagation up the DOM tree. Remove to allow propagation.
});
// When mouse enters the active area of a link with class "fancy-hover",
// tell all links in the class which member of the class has the mouse.
$("a.fancy-hover").mouseenter(function() {
// this.id is ID of current element,
// and we pass the value as an array to our custom event.
$("a.fancy-hover").trigger('mouseOverOneOfUs', [this.id]);
});
</script>
「我有一對夫婦的綁定到自定義事件的聯繫。本次活動由任何徘徊這些鏈接觸發。不過,我不希望它被我居然徘徊的鏈接觸發的事。」你真的要解釋。這沒有太大的意義。 – Jere 2010-12-05 13:27:31