Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在同一表单中获取更新的多选下拉列表数据_Javascript_Php_Bootstrap 4 - Fatal编程技术网

Javascript 如何在同一表单中获取更新的多选下拉列表数据

Javascript 如何在同一表单中获取更新的多选下拉列表数据,javascript,php,bootstrap-4,Javascript,Php,Bootstrap 4,我的应用程序使用bootstrap、js和php。我用bootstrap获得了multiselect下拉列表。第一次添加数据效果很好。当有人在我的应用程序中单击edita按钮时,我可以从数据库中检索信息,并获得与第一次相同的预选数据。现在,如果用户更改选择,我将无法使其工作。我可以将数据提取到js变量,但在将其设置为html id时出现问题。它变为null。如果我不能分配给html id,我就无法使用它 $(function(){ // $('.multi').multiselect("

我的应用程序使用bootstrap、js和php。我用bootstrap获得了multiselect下拉列表。第一次添加数据效果很好。当有人在我的应用程序中单击edita按钮时,我可以从数据库中检索信息,并获得与第一次相同的预选数据。现在,如果用户更改选择,我将无法使其工作。我可以将数据提取到js变量,但在将其设置为html id时出现问题。它变为null。如果我不能分配给html id,我就无法使用它

$(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。