jQuery的可變數目:jQuery的克隆格內容的時間
$('#partsOrderQty').blur(function(){
var rowCounter = $(this).val();
console.log(rowCounter);
var toAddRow = $("#skidListings").children().clone();
for (var i=0; i<rowCounter; i++) {
$("#skidListings").append(toAddRow);
console.log("Ran Once Just Now");
}
});
HTML:
<div id="skidListings">
<input class="ConfirmQty" name="ConfirmQty" type="text" value="<?php echo $confirm;?>"/>
<input class="ConfirmDesc" name="ConfirmDesc" type="text" value="<?php echo $des[$final]; ?>"/>
<input class="ConfirmWeight" name="ConfirmWeight" type="text" value="<?php echo $ShipWeight[$final]*$confirm; ?>" />
<input class="ConfirmClass" name="ConfirmClass" type="text" value="<?php echo $class[$final]; ?>"/>
<input class="ConfirmNMFC" name="ConfirmNMFC" type="text" value="<?php echo $NMFC[$final]; ?>"/>
<input class="ConfirmLength" name="ConfirmLength" type="text" value="<?php echo $length[$final]; ?>"/>
<input class="ConfirmWidth" name="ConfirmWidth" type="text" value="<?php echo $width[$final]; ?>" />
<input class="ConfirmHeight" name="ConfirmHeight" type="text" value="<?php echo $height[$final]; ?>" /><br />
</div>
爲什麼這隻克隆一次,即使它打印控制檯消息的時間正確的金額是多少?我必須清除這些值嗎?該功能允許我手動指定不同於從數據庫中提取的數量的碎片。我明白我不能用ID來克隆東西,但是我選擇了孩子,但沒有一個人有ID。我需要保留這些類,如果我刪除了名字?這很重要嗎?
編輯:爲每個請求http://jsfiddle.net/NxSwA/
只是好奇,如果你意識到並關心你的代碼和答案都會重複所有的內容?所以如果你第一次有1到addRow ...你會得到2 ...但是如果你再加1,你會得到4,然後是8等 – smerny
說實話,我不指望我用戶不止一次地改變它(我只有兩個預期的用戶),但是之前我沒有做過這些事情,所以我會照顧相應的改變。 –