我有以下内容
var $header = $('.inner th');
var $fixedHeader = $(".header1 th");
$header.each(function (index) {
// i need to copy all events from $header[index] to $fixedHeader[index]
});
如何将事件处理程序(onClick、onDblClick 等)从第一个集合中的元素复制到第二个集合中的相邻元素?我是 jquery 的新手,遇到了困难。
我知道这个问题已经被回答过几次了,但这里有一个基于以前的解决方案的全包解决方案。
function copyEvents(source, destination) {
var events;
//copying from one to one or more
source = $(source).first();
destination = $(destination);
//get all the events from the source
events = $(source).data('events');
if (!events) return;
//make copies of all events for each destination
destination.each(function() {
var t = $(this);
$.each(events, function(index, event) {
$.each(event, function(i, v) {
t.bind(v.type, v.handler);
});
});
});
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)