我如何知道为链接设置了 onmousedown 事件?

发布于 2024-08-25 11:53:39 字数 93 浏览 7 评论 0原文

我想在加载 html 文档后对其进行解析,并发现为它们设置 onmousedown 事件的所有链接 - 我该如何做到这一点?

谢谢

亚历克斯

I want to parse an html document after it has loaded and discover all the links that the onmousedown event is set for them - how do I do that?

Thanks

Alex

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

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

发布评论

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

评论(2

你げ笑在眉眼 2024-09-01 11:53:39

虽然您无法直接执行此操作,但您可以通过使用几个内置函数来创建具有 onmousedown 属性的元素数组。

// get all anchor tags
var anchors = document.getElementsByTagName('a');
// empty array to store matches in
var matches = [];

// loop through all anchors
for (var i = 0, len = anchors.length; i < length; i++)
{
    // if there is an onmousedown function, add it to the array
    if (typeof anchors[i].onmousedown === 'function')
    {
         matches.push(anchors[i]);
    }
}

While you can't do this directly, you can create an array of elements with the onmousedown property by using a couple of inbuilt functions.

// get all anchor tags
var anchors = document.getElementsByTagName('a');
// empty array to store matches in
var matches = [];

// loop through all anchors
for (var i = 0, len = anchors.length; i < length; i++)
{
    // if there is an onmousedown function, add it to the array
    if (typeof anchors[i].onmousedown === 'function')
    {
         matches.push(anchors[i]);
    }
}
故事和酒 2024-09-01 11:53:39

我认为你不能。

如果您的脚本之一设置了 onmousedown 事件,您可以修改它,以便它向您设置事件处理程序的 dom 元素添加一个属性,以便您稍后可以测试该属性。

I don't think you can.

If it's one of your script that sets the onmousedown event, you can modify it so it adds an attribute to the dom elements you set an event handler, so you can test that attribute later.

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