所以我正在尝试使用 Jquery 克隆功能。我的问题是第一个克隆还可以。然后下一个总是附加两次。
JS
var initpriceinquiry = function(){
$(document).on("click",".btn_addMore_unit",function () {
var cloned = $(".price_inquiry_source tbody ").html();
var oldL = $(".units").length;
cloned = cloned.replace(/\[\x\]/g,oldL);
$(cloned).insertBefore("#targetRow");
modSelect2("select[name='pi_product_id[]']","/admin/price_inquiry/get_ajax_input?type=product_id&custom_type",function(obj) {
$.ajax({url:"", type: "get", data:"get_unit=1&product_id="+obj.val(), success: function(data)
{
eval("var record = "+data+";");
obj.parent().next().html(record[0]);
obj.parent().next().next().html(record[1]);
obj.parent().next().next().next().html("<textarea name = 'remark' class = 'form-control'></textarea>");
} });
});
});
}
HTML
<table class = 'hidden price_inquiry_source'>
<tr class = 'units'>
<td >
<select name = 'pi_product_id[]' class = 'form-control unitcodes[x]' style="width:120px">
</select>
<br>
<a href='javascript:void(0)' style='' onclick="$(this).parent().parent().remove();" class=''><i class='fa fa-trash'></i></a>
</td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
{{-- To BE CLONED --}}
克隆的应该插入这里
<table class="table table-condensed table-hover" id = "tableData">
<thead>
<tr>
<th>UNIT CODE</th>
<th>DESCRIPTION</th>
<th>SELLING PRICE</th>
<th>REMARKS</th>
</tr>
</thead>
<tbody>
<tr id = 'targetRow'>
<td colspan="4"><button class="btn btn-link btn_addMore_unit"
href="javascript:void(0)" style="display: inline-block;"><i class="fa fa-
plus "></i> ADD UNIT</a></td>
</tr>
</tbody>
</table>
有关我的问题,请参阅附加图片
任何帮助将不胜感激谢谢!