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

标签 javascript jquery onmouseover

我想为页面中的所有 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/

相关文章:

javascript - 全屏菜单只出现在导航栏中

c# - 通过 javascript 将复杂对象传递到 .Net 服务

jquery - 当首选(外部/服务器/远程/云)图像加载失败时,有没有办法提供后备(本地)图像?

javascript - 使用分类 ("active"鼠标悬停时 D3 颜色变化,真)

javascript - onmousemove 事件未触发

css - 由文本控制的鼠标悬停横幅

javascript - Passport 出现 CORS 错误 LinkedIn 策略

javascript - 切换最近的 div 位置

javascript - 在 chrome 扩展中使用 Chrome 文字转语音

javascript - 延迟对象链可以用于事件处理程序吗?