雖然對於我需要學習的東西,我並不熟悉Jquery。我目前有一個我正在開發的項目,它需要一個類似於發票上的添加/刪除功能。Jquery - 刪除最後一個附加項
我希望能夠將「刪除」功能添加到追加的最後一個項目櫃面失誤獲得由等
$(document).ready(function() {
var currentItem = 1;
$('#addnew').click(function(){
currentItem++;
$('#items').val(currentItem);
var strToAdd = '<br>Product: <select class="form" name="Product'+currentItem+'" id="product'+currentItem+'" ><option value="Aramax Classic Tobacco">Aramax Classic Tobacco</option><option value="Aramax Energy Drink">Aramax Energy Drink</option></select> Nicotine: <select class="form" name="nicotine'+currentItem+'" id="nicotine'+currentItem+'"> <option value="N/A">n/a</option><option value="3mg">3mg</option><option value="6mg">6mg</option><option value="12mg">12mg</option></select> Quantity:<input class="form3" name="qty'+currentItem+'" id="qty'+currentItem+'" type="number" /><br>';
$('#data').append(strToAdd);
});
});
$('#delete').on('click', function() {
$('#items').parents("br").remove();
});
//]]>
</script><div class="form2">
<form method="POST" action="invoicereg.php" id="data" name="sub">
Product:
<select class="form" name="product1" id="product1">
<option value="Aramax Classic Tobacco">Aramax Classic Tobacco</option>
<option value="Aramax Energy Drink">Aramax Energy Drink</option>
</select>
Nicotine:
<select class="form" name="nicotine1" id="nicotine1">
<option value="N/A">n/a</option>
<option value="3mg">3mg</option>
<option value="6mg">6mg</option>
<option value="12mg">12mg</option>
</select>
Quantity:<input class="form3" type="number" id="qty1" name="qty1"></input><br>
</form>
<br>
<input class="button" type="button" id="addnew" name="addnew" value="Add new item" />
<input type="hidden" form="data" id="items" name="items" value="1" />
<input class="button" type="button" id="delete" name="delete" value="Remove" />
<input class="button" type="submit" form="data" value="SUBMIT">
</div>
</div>
</body>
</html>
如果任何人都可以顯示和/或向我解釋如何做到這一點,將不勝感激。 Regards
將添加一個刪除選項添加到每個新行或您想只是最後一個有d elete選項...? – Bsienn