本文介绍了使用jQuery将事件处理程序从一组元素复制到另一组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下内容
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..etc)从第一组元素复制到第二组相邻元素?我是jquery的新手,很难过.
How do I copy the event handlers (onClick, onDblClick..etc) from elements in the first set to the adjacent elements in the second set?? I am novice to jquery and having hard time.
推荐答案
您需要使用jquery的 .data (事件")方法.
You need to use jquery's .data('events') method.
我提供了一个可用的jsFiddle,以了解从哪里开始.
I've provided a working jsFiddle to get an idea of where to start.
我知道Alphamale击败了我,但如果有帮助,我仍然会发布它.
I know Alphamale beat me, but I'm still going to post it incase it's helpful.
反正几乎相同...
这篇关于使用jQuery将事件处理程序从一组元素复制到另一组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!