我有一個名爲'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