我想为页面中的所有锚标记添加OnMouseOver。但我,如果任何锚标签已经有一个OnMouseOver,即使我不想替换它。我只想在那里添加我的事件处理程序。
我如何通过Javascript或JQuery实现它?
答案 0 :(得分:2)
默认行为是添加而不是替换事件,所以只需使用.mouseover()
,如下所示:
$(function() {
$('a').mouseover(function() {
//do something
alert('My url is: ' + this.href);
});
});
Give it a try here。或者也许你在.hover()
之后,例如,如果你有color plugin或jQuery UI并且想要为颜色设置动画:
$(function() {
$('a').hover(function() {
$(this).animate({ color: '#123456' });
}, function() {
$(this).animate({ color: '#000099' });
});
});