2010-08-07 73 views
0

即使對於頁面中的所有錨定標記,我也想附加OnMouseOver。但是,如果任何錨標籤已經有一個OnMouseOver,即使我不想替換它。我只想在那裏添加我的事件處理程序。爲頁面中的所有URL附加OnMouseOver事件

如何通過Javascript或JQuery實現它?

回答

2

的默認行爲是添加不能代替一個事件,所以只需使用.mouseover(),像這樣:

$(function() { 
    $('a').mouseover(function() { 
    //do something 
    alert('My url is: ' + this.href); 
    }); 
}); 

Give it a try here。或者,也許你.hover()後,例如,如果你有color pluginjQuery UI,你想動畫的顏色:

$(function() { 
    $('a').hover(function() { 
    $(this).animate({ color: '#123456' }); 
    }, function() { 
    $(this).animate({ color: '#000099' }); 
    }); 
}); 

You can give it a try here

相關問題