在下面的代码中,我尝试循环遍历每个子节点并将子节点附加到另一个元素 - 循环内的正确语法是什么?
$(this).children().each(
$(div).appendChild(this.childNodes.length - 1);
);
最佳答案
在 each()
函数中,this
指的是您要迭代的对象,在本例中为 children()
。它不是原始 jQuery 对象的 this
。
因此:
$(this).children().each(function() {
$(div).appendChild($(this));
});
关于jQuery 为每个附加子节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1379452/