Javascript 如何在同一表单中获取更新的多选下拉列表数据
我的应用程序使用bootstrap、js和php。我用bootstrap获得了multiselect下拉列表。第一次添加数据效果很好。当有人在我的应用程序中单击edita按钮时,我可以从数据库中检索信息,并获得与第一次相同的预选数据。现在,如果用户更改选择,我将无法使其工作。我可以将数据提取到js变量,但在将其设置为html id时出现问题。它变为null。如果我不能分配给html id,我就无法使用它Javascript 如何在同一表单中获取更新的多选下拉列表数据,javascript,php,bootstrap-4,Javascript,Php,Bootstrap 4,我的应用程序使用bootstrap、js和php。我用bootstrap获得了multiselect下拉列表。第一次添加数据效果很好。当有人在我的应用程序中单击edita按钮时,我可以从数据库中检索信息,并获得与第一次相同的预选数据。现在,如果用户更改选择,我将无法使其工作。我可以将数据提取到js变量,但在将其设置为html id时出现问题。它变为null。如果我不能分配给html id,我就无法使用它 $(function(){ // $('.multi').multiselect("
$(function(){
// $('.multi').multiselect("refresh");
var brands;// = $('#pSpecial option:selected');
var specials;// = [];
$('.multi').multiselect({
includeSelectAllOption:true,
enableCaseInsensitiveFiltering: true,
enableFiltering:true,
maxHeight: '275',
buttonWidth: '180',
onChange: function(element, checked) {
brands = $('#pSpecial option:selected');
specials = [];
$(brands).each(function(brand){
specials.push([$(this).val()]);
});
console.log(specials);
alert(specials);
$("#pSpecial").val(specials);
alert(document.getElementById('pSpecial').value);
}
});
$('.multi').multiselect("refresh");
});
我的代码没有语法错误。未能执行$pSpecial.valspecials 是“特价商品”工作?是的,正在工作@KunalRaut.is`alertspecials;`工作?是的,它在工作@KunalRaut。