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

发布于 2024-09-13 16:12:23 字数 123 浏览 7 评论 0原文

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

我如何通过 Javascript 或 JQuery 实现它?

I want to attach OnMouseOver even for all the anchor tags in a page. But i if any of the anchor tags already has a OnMouseOver even i dont want to replace it. I just want to add my event handler there.

How can i achieve it through Javascript or JQuery?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

天煞孤星 2024-09-20 16:12:23

默认行为是添加而不是替换事件,因此只需使用。 mouseover(),如下所示:

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

在这里尝试一下。或者也许您在 .hover() 之后,例如,如果您有 颜色插件jQuery UI 并且您想要为颜色设置动画:

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

您可以给它在这里尝试一下

The default behavior is to add not replace an event, so just use .mouseover(), like this:

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

Give it a try here. Or maybe you're after .hover(), for example if you had the color plugin or jQuery UI and you wanted to animate the color:

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

You can give it a try here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文