如何使用小书签删除内联 onclick 属性?

发布于 2024-08-27 06:03:11 字数 303 浏览 8 评论 0原文

有一个烦人的网站,它通过使用

如何删除原来的 onclick 处理程序?

There is an annoying website out there that foils attempts to "open in new tab" by using <div onclick=> instead of <a href=>. I've written a bookmarklet, using jQuery, that creates a wrapper <a> tag and inserts it within the <div> around its content.

How can I remove the original onclick handler?

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

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

发布评论

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

评论(3

欲拥i 2024-09-03 06:03:11

还没有提到:

$('#myId')[0].onclick = null; // remove the inline onclick() event

Not mentioned yet:

$('#myId')[0].onclick = null; // remove the inline onclick() event
遥远的绿洲 2024-09-03 06:03:11

未经测试,但是......

$("selector").removeAttr("onclick");

我想你已经尝试过

$("selector").unbind("click");

Untested, but...

$("selector").removeAttr("onclick");

I guess you have already tried to

$("selector").unbind("click");
烙印 2024-09-03 06:03:11

在某些情况下,将 onclick 设置为 null 不起作用,但这应该始终有效:

document.getElementById("myId").setAttribute("onclick", "");

In some circumstances setting onclick to null won't work, but this should always work:

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