从 复制事件处理程序到;一个元素到另一个元素
我不认为任何类似的现有问题可以回答这个问题。
我正在开发一个插件,它将把 转换为具有两个切换状态的
。使用的基本思想是:$('div .checkboxContainer').prettyBox();
插件本身的伪代码是:
$.fn.prettyBox = function(){
return this.each(function(){
$(this).find(':checkbox').each(function(){
.. grab all event handlers on the current <input>
.. create a new <div>
.. attach all of the <input>'s event handlers to the <div>
.. hide the <input>
.. place the <div> where the <input> used to live
});
};
};
其他提出类似问题的人一直关心复制单个事件,例如 click
处理程序。为了保持插件的灵活性,我认为我的代码循环遍历附加到输入的所有内容并将其复制过来很重要。
I don't believe any similar existing questions answer this one.
I am developing a plugin that will turn <input type='checkbox' />
into a <div>
with two toggle states. The basic idea for use is:
$('div .checkboxContainer').prettyBox();
The pseudo code for the plugin itself is:
$.fn.prettyBox = function(){
return this.each(function(){
$(this).find(':checkbox').each(function(){
.. grab all event handlers on the current <input>
.. create a new <div>
.. attach all of the <input>'s event handlers to the <div>
.. hide the <input>
.. place the <div> where the <input> used to live
});
};
};
Others who have asked similar questions have been concerned with copying single events, such as a click
handler. To maintain plugin flexibility, I think it's important that my code loop through everything attached to the input and copy it over.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个
Try this
我认为如果事件也使用 jQuery 绑定,您可以使用 $('#elem').data("events")
来源: https://stackoverflow.com/questions/2518421/jquery-find-events-handlers-registered-with-an-object
I think if the events are also bound using jQuery, you can get all events using $('#elem').data("events")
Soure: https://stackoverflow.com/questions/2518421/jquery-find-events-handlers-registered-with-an-object