gpt4 book ai didi

javascript - 为页面中的所有 URL 附加 OnMouseOver 事件

转载 作者:行者123 更新时间:2023-12-02 20:35:07 25 4
gpt4 key购买 nike

我想为页面中的所有 anchor 标记附加 OnMouseOver。但如果任何 anchor 标记已经有 OnMouseOver,即使我不想替换它。我只想在那里添加我的事件处理程序。

如何通过 Javascript 或 JQuery 实现它?

最佳答案

默认行为是添加而不是替换事件,因此只需使用 .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

关于javascript - 为页面中的所有 URL 附加 OnMouseOver 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3430071/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com