我正在尝试选择一个动态更新的字段。我已经做到了,但是我的页面上有一个“加号”按钮,单击该按钮会添加其他select
字段
如何使加号按钮添加的select
字段本身也更新?
这是我的动态select
和加号按钮的代码。我单击加号按钮后再次尝试动态选择,但是没有运气,也许我的代码本身是错误的
$(document).ready(function($) { //dinamic select
$('#subsidiary_add').change(function() {
$.get("{{ url('compras/ordem_compra/retorna_pedido')}}", {
id_subsidiary: $(this).val()
},
function(data) {
var model = $('#id_pedido_compra_add');
model.empty();
$.each(data, function(key, value) {
model.append("<option value='" + key + "'>" + value + "</option>");
});
}
);
});
});
var counter = 0;
$('.modal-body').on('click', '#add', function() { // "plus button"
$('#plusbutton').append(
"<label for='id_pedido_compra' class='col-md-2 col-form-label added'>Descrição</label>" +
"<div class='form-group col-md-4 added'>" +
"<select class='form-control' name='id_pedido_compra" + counter + "' id='teste'>" +
"<option selected='selected' value>...</option>" +
"</select>" +
"</div>" +
"<label for='quantidade_comprada' class='col-md-2 col-form-label added'>Quantidade</label>" +
"<div class='form-group col-md-4 added'>" +
"<input id='quantidade_comprada' class='form-control' name='quantidade_comprada" + counter + "' type='text'>" +
"</div>"
);
counter++;
});