假设我有这个jQuery扩展方法:
这个还是这个吗?
$.fn.foobar = function() {
var clone = this.parent().clone();
};
在我使用clone
后,如何找到与this
相同的克隆子元素?
这样行吗?
$.fn.foobar = function() {
var clone = this.parent().clone();
var cloneOfThis = clone.find(this);
};
这个还是这个吗?
$.fn.foobar = function() {
var clone = this.parent().clone();
var self = this;
var cloneOfThis;
clone.children().each(function() {
var $this = $(this);
if ($this === self) {
cloneOfThis = $this;
}
});
};
this
引用选择器选中的元素数组之外,为什么不克隆父元素和当前元素? - Felix Klingthis
克隆体。一个是直接克隆的,另一个是随其父级一起克隆的。 - user113716