javascript cloneNode与事件 [英] javascript cloneNode with events

查看:88
本文介绍了javascript cloneNode与事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为gmail制作一个greasemonkey脚本,我需要制作收件箱链接的副本。使用cloneNode工作正常,但我认为有一个onclick事件会在运行时附加到它。所以,这是一个两部分问题:
1.是否有办法查看附加到节点的事件?
2.是否有办法复制这些事件?
我发现的最接近的是jQuery,我还没有准备好去那里。
谢谢!

I am working on a greasemonkey script for gmail where i need to make a copy of the "Inbox" link. Using cloneNode works ok, but i think there's an onclick event that gets attached to it at runtime. So, this is a two part question: 1. Is there a way to see what events are attached to a node? 2. Is there a way to copy those events as well? The closest thing i found was jQuery, and i am not ready to go there yet. Thanks!

推荐答案


  1. 除非使用 onclick 属性。

  2. 不可靠(您可以复制 onclick 属性,但不管将继续工作,取决于它是否被使用以及它是干什么的)。

  1. Not unless it's set using the onclick attribute on the element.
  2. Not reliably (you can copy the onclick attribute, but whether that will continue to work depends on if it was used and what it does).

你最好添加你自己的点击处理程序,然后触发原始事件...或以其他方式模拟行为。

You're better off adding your own click handler, and then triggering that event on the original... Or simulating the behavior in some other way.

这篇关于javascript cloneNode与事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆