【发布时间】:2017-10-25 16:38:53
【问题描述】:
我想使用 jQuery 克隆 div 的内容,但是从复制的内容中,我想在使用 appendTo 函数之前从原始内容中删除该类。当我从克隆中删除类时,它们也会从原始类中删除。
我的代码是:
$('.carousel .item').each(function(){
var next = $(this).next();
if (!next.length) {
next = $(this).siblings(':first');
}
next.children(':first-child').clone().appendTo($(this));
next.children(':first-child').addClass('col-sm-offset-1');
for (var i=0;i<3;i++) {
next=next.next();
if (!next.length) {
next = $(this).siblings(':first');
}
next.children(':first-child').clone().appendTo($(this));
}
});
请注意,我不想从复制内容的实际 div 中删除类,我只想从复制的代码中删除它,以便它不包含在克隆的 div 中。
【问题讨论】:
-
我没有看到删除类的代码,你能用删除类更新你的代码吗,你在哪里尝试删除类
-
next.children(':first-child').removeClass('col-sm-offset-1').clone().appendTo($(this)); //这里我删除了克隆的 div 类
标签: javascript jquery twitter-bootstrap bootstrap-modal