Select2在我的所有字段中都起作用,除了表中列出的字段
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/css/select2.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/js/select2.min.js"></script>
<script>
$(document).ready(function(){
$(document).on('click', '.add', function(){
var html = '';
html += '<tr>';
html += '<td><input type="text" name="item_name[]" class="form-control qty_onhand" /></td>';
html += '<td><input type="text" name="qty_need[]" class="form-control qty_need" /></td>';
html += '<td><select name="item_unit[]" class="js-example-basic-single form-control item_unit"><option value="">Select Unit</option><?php echo fill_unit_select_box($connect); ?></select></td>';
html += '<td><button type="button" name="remove" class="btn btn-danger btn-sm remove"><span class="glyphicon glyphicon-minus"></span></button></td></tr>';
$('#item_table').append(html);
});
</script>
<script type="text/javascript">
$('.js-example-basic-single').select2({
placeholder: 'Select an option'
});
</script>
class =“ js-example-basic-single-form-control item_unit”我添加了该类,但未应用select2