jQuery的最接近格取出未工作我發現同樣的問題在計算器,但這些不回答,解決我的問題jQuery的:最近()DIV取出未工作
closest div remove js fiddle here
<script>
$(document).ready(function(){
var counter = 4;
var name = 1;
var qty = 1;
var price = 1;
$('#addproduct').click(function() {
$('#dynamicInput').append('<div class="clearfix"></div><div class="pdd" id="dlt"><div class="col-sm-3"><div class="row">' + (counter++)+' <label>Product Name</label></div></div><div class="col-sm-3"><div class="row"><select name="productnm'+(name++)+'"><option>Select Product</option><option>Rice</option><option>Fried Rice</option><option>Biryani</option></select></div></div><div class="col-sm-3"><div class="row"><label>Quantity</label></div></div><div class="col-sm-1 row"><div class="row qunatity-number"><input type="number" name="qunatity'+(qty++)+'" value="1" /></div></div><div class="col-sm-2"><div class="row qunatity-totalprice"><input type="text" name="totalprice'+(price++)+'" placeholder="Total Price" disabled /></div></div><a class="deleter" ><i class="fa fa-trash-o" aria-hidden="true"></i></a></div> ');
});
$('.deleter').click(function(){
$(this).closest("#dlt").remove();
});
});
</script>
可能重複的[Jquery事件處理程序不工作在動態內容](https://stackoverflow.com/questions/15090942/jquery-event-handler-not-working-on-dynamic-content) – trincot