我有一个名为'div.cloneFrame'的div,我使用jquery.clone来克隆它。它工作正常,我克隆所有我需要的,使用此功能:Jquery colone child count issue(nnth-child)
var needToClone = 4;
var totalImgs = 0;
for(i=0;i<needToClone;i++){
$('div.cloneFrame').clone()
.removeClass('cloneFrame')
.appendTo('.frame-group').each(function(){
var imgSrcLength = $(this).find('img');
for(j=0;j<imgSrcLength.length;j++){
totalImgs++;
$(imgSrcLength[j]).attr('src','imgs/outfits/'+totalImgs+'.jpg');
}
})
}
$('div.cloneFrame').remove();
后,我需要选择克隆DIV,为我使用第n个子功能
$('div.myframe:nth-child('+1+')').addClass('incoming').next().addClass('outgoing');
但不起作用。如果我使用这种方式:
$('div.myframe:nth-child('+3+')').addClass('incoming').next().addClass('outgoing');
它运作良好。为什么它需要在第n个孩子上扫2个数字?我身边有什么不对?
我的HTML:
<div class="frame-group">
<div class="cloneFrame myframe">
<div id="orange-frame" class="product-frame">
<a class="purchase-btn" href="#">Purchase this item</a>
<img alt="women coat" src="imgs/yellow-coat.jpg">
</div>
<div id="yellow-frame" class="product-frame">
<a class="purchase-btn" href="#">Purchase this item</a>
<img alt="blue coat" src="imgs/coat-blue.jpg">
</div>
<div id="brown-frame" class="product-frame">
<a class="purchase-btn" href="#">Purchase this item</a>
<img alt="women shoe" src="imgs/women-shoe.jpg">
</div>
<div id="green-frame" class="product-frame">
<a class="purchase-btn" href="#">Purchase this item</a>
<img alt="women jean" src="imgs/jean.jpg">
</div>
</div>
<span class="outfit-no">outfit no.<span>01</span></span>
<a class="buy-outfit" href="#">Buy outfit</a>
</div>
,请访问:http://jsbin.com/iquxaq/3