0
我的困境是,我無法弄清楚如何複製表時,表的克隆副本中保持我的運算功能。我非常感謝任何見解,哪一個纔是最有效的方式?jQuery的克隆和追加,但保留複製腳本
$(document).ready(function() {
$("#add2").click(function() {
$("#clone").clone().appendTo("body");
});
});
$(document).ready(function() {
var basePrice = 6.25;
$(".calculate").change(function() {
newPrice = basePrice;
$(".calculate option:selected").each(function() {
newPrice += Number($(this).data('price'));
});
$("#item-price").html(newPrice.toFixed(2));
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<div id="clone">
<fieldset id="fspace2">
<legend>Project Details</legend>
<table>
<tr>
<td style="padding-bottom:1em;">
<label for="title">Title:</label>
<input type="text" name="title" id="title">
</td>
 
<td style="padding-bottom:1em;">
<label for="title">Price:</label>
<span id="item-price" </span>
<br />
</td>
</tr>
</table>
<table id="line">
<tr>
<td class="titlecust" style="text-align: center; width:2em;">Options & Packages</td>
</tr>
<tr>
<td class="cellspace">
<!--**OPT - Come back to fix spacing-->
<br />
<select class="form-control calculate" id="try" name="try">
<option data-price="0" value="select">Select an Option</option>
<option data-price="208" value="logo1">cookies</option>
<option data-price="650" value="bro">pizza</option>
<option data-price="400" value="web1">brownies</option>
<option data-price="N/A" value="oth">Other</option>
</select><br /><br />
<select class="form-control calculate" id="packaging" name="packaging">
<option data-price="0" value="standard">Choose a Package</option>
<option data-price="322.20" value="shrink">Pink</option>
<option data-price="659.70" value="shrink">Blue</option>
</select><br />
</td>
</table>
</fieldset>
<br />
<button id="add2">Clone Stuff</button>
還要注意的是,如果你使用克隆ID的元素,建議更改爲ID,這樣你就不必重複的ID。 –
謝謝卡爾!你是最好的! –