我通过 jquery 在表中添加了新行,然后 select2 不起作用
// Javascript
$("#add").click(function () {
$("#mytable").each(function () {
var tds = '<tr>';
jQuery.each($('tr:last td', this), function () {
tds += '<td>' + $(this).html() +'</td>';
});
tds += '</tr>';
if ($('tbody', this).length > 0) {
$('tbody', this).append(tds);
} else {
$(this).append(tds);
}
});
});
//HTML
<form method="POST" action="/store">
{{ csrf_field() }}
<h2>Invoice</h2>
<div>
<!-- Customer job-->
<div class="form-group job">
Customer job:
<select class="customer_job" name="customer_job">
@if(count($customers)>1)
@foreach($customers as $customer)
<option>{{$customer ->job}}</option>
@endforeach
@else
<p>No posts found</p>
@endif
</select>
</div>
<!--Date-->
<div class="form-group date">
Date:
<input type="date" name="date">
</div>
</div>
<br><br>
<table id="mytable">
<tr>
<th>ITEM</th>
<th>DESCRIPTION</th>
<th>QUANTITY</th>
<th>RATE</th>
<th>AMOUNT</th>
</tr>
杨魅力