Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/410.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 Jquery第二个下拉列表(取决于第一个下拉列表)不会更改_Javascript_Jquery - Fatal编程技术网

Javascript Jquery第二个下拉列表(取决于第一个下拉列表)不会更改

Javascript Jquery第二个下拉列表(取决于第一个下拉列表)不会更改,javascript,jquery,Javascript,Jquery,您好,我有过滤第二个下拉菜单的问题,这取决于第一个下拉菜单,就像第二个下拉菜单选项一样,它们是静态的,不会根据我选择的内容进行更改。这里是获取secon下拉菜单数据的代码 $.ajax({ dataType: "json", url: "{{action('CampaignController@getAdvertiser')}}/"+$("#advertiserId").val() }).done(function(results){

您好,我有过滤第二个下拉菜单的问题,这取决于第一个下拉菜单,就像第二个下拉菜单选项一样,它们是静态的,不会根据我选择的内容进行更改。这里是获取secon下拉菜单数据的代码

   $.ajax({
        dataType: "json",
        url: "{{action('CampaignController@getAdvertiser')}}/"+$("#advertiserId").val()

    }).done(function(results){
        $("#brandId").empty();
        $(results).each(function(index,value){                          

             newOption = $("<option value=\""+value.id+"\">"+value.brandName+"</option>");
             $("#brandId").append(newOption);



        }); 
$.ajax({
数据类型:“json”,
url:“{{action('CampaignController@getAdvertiser“)}}/”+$(“#广告客户ID”).val()
}).完成(功能(结果){
$(“#brandId”).empty();
$(结果)。每个(函数(索引,值){
newOption=$(“”+value.brandName+“”);
$(“#brandId”).append(新选项);
}); 
请检查我的整个脚本,也许某个地方正在刷新该下拉列表

    $(document).ready(function () {
        $(function () {
            $("#multiselect").multiselect({
                includeSelectAllOption: true
            });
            $('#btnSelected').click(function () {
                var selected = $("#multiselect option:selected");
                var message = "";
                selected.each(function () {
                    message += $(this).text() + " " + "\n";
                });
                alert(message);
            });
        });

        function loadBrands() {

            $.ajax({
                dataType: "json",
                url: "{{action('CampaignController@getAdvertiser')}}/" + $("#advertiserId").val()
            }).done(function (results) {
                $("#brandId").empty();

                $.each(results, function (index, value) {

                    var newOption = $("<option value=\"" + value.id + "\">" + value.brandName + "</option>");
                    $("#brandId").append(newOption);
                    // $("#brandId").trigger("chosen:updated");
                });
                //$("#brandId").empty();
                // hardcode 1 it must be remove asap
                $.ajax({
                    dataType: "json",
                    url: "{{action('ReportingController@getCamp')}}/" + 1
                }).done(function (results) {
                    $("#campaignId").empty();
                    console.debug(get);
                    $(results).each(function (index, value) {

                        $("#campaignId").append("<option value=\"" + value.campaignId + "\">" + value.campaignName + "</option>");
                        $('#campaignId').trigger('change');
                    });
                });
                //loading city
                $.ajax({
                    dataType: "json",
                    url: "{{action('CampaignLocationController@getLocations')}}/" + 1
                }).done(function (results) {
                    $("#city").empty();

                    $(results).each(function (index, value) {
                        getCityDetails = value.data[0];

                        $("#city").append("<option value=\"" + getCityDetails.brandId + "\">" + getCityDetails.city + "</option>");
                        $('#city').trigger('change');
                    });
                });

            }).fail(function (results) {
                alert("Failed to load brands.");
            });
        }
        loadBrands();
        $("#advertiserId").change(loadBrands);
        $("#brandId").change(loadBrands);


    });
$(文档).ready(函数(){
$(函数(){
$(“#多选”)。多选({
includeSelectAllOption:true
});
$(“#b选择”)。单击(函数(){
所选变量=$(“#多选选项:已选”);
var message=“”;
已选定。每个(函数(){
消息+=$(this).text()++++“\n”;
});
警报(信息);
});
});
函数loadBrands(){
$.ajax({
数据类型:“json”,
url:“{{action('CampaignController@getAdvertiser“)}}/”+$(“#广告客户ID”).val()
}).完成(功能(结果){
$(“#brandId”).empty();
$.each(结果、函数(索引、值){
var newOption=$(“”+value.brandName+“”);
$(“#brandId”).append(新选项);
//$(“#brandId”).trigger(“已选择:已更新”);
});
//$(“#brandId”).empty();
//硬代码1必须尽快将其删除
$.ajax({
数据类型:“json”,
url:“{{action('ReportingController@getCamp')}}/" + 1
}).完成(功能(结果){
$(“#活动ID”).empty();
调试(get);
$(结果)。每个(函数(索引、值){
$(“#活动ID”).append(“+value.campaigname+”);
$(“#活动ID”).trigger('change');
});
});
//装货城市
$.ajax({
数据类型:“json”,
url:“{{action('CampaignLocationController@getLocations')}}/" + 1
}).完成(功能(结果){
$(“#城市”).empty();
$(结果)。每个(函数(索引、值){
getCityDetails=value.data[0];
$(“#city”).append(“+getCityDetails.city+”);
$('city')。触发('change');
});
});
}).失败(功能(结果){
警报(“未能加载品牌”);
});
}
loadBrands();
$(“#广告客户ID”)。更改(loadBrands);
$(“#brandId”)。更改(loadBrands);
});
用于在jQuery中迭代节点列表

对于数据操作,必须使用
$。每个(结果)

$.each(results, function(index,value){                          

            var newOption = $("<option value=\""+value.id+"\">"+value.brandName+"</option>");
             $("#brandId").append(newOption);
            // $("#brandId").trigger("chosen:updated");


        }); 
$。每个(结果、函数(索引、值){
var newOption=$(“”+value.brandName+“”);
$(“#brandId”).append(新选项);
//$(“#brandId”).trigger(“已选择:已更新”);
}); 
不必在每次迭代中追加,您可以推送到一个数组,然后在最后追加它

var options = [];
$.each(results, function(index,value){                          
   options.push('<option value="'+value.id+'">'+value.brandName+'</option>');  
}); 
$("#brandId").html(options.join());
var选项=[];
$.each(结果、函数(索引、值){
options.push(“”+value.brandName+“”);
}); 
$(“#brandId”).html(options.join());
另外,您在定义
newOption
时错过了
var
关键字,因此它将是全局的{
$(document).ready(function() {
$(function () {
$("#multiselect").multiselect({
    includeSelectAllOption: true
});
$('#btnSelected').click(function () {
    var selected = $("#multiselect option:selected");
    var message = "";
    selected.each(function () {
        message += $(this).text() + " " + "\n";
    });
    alert(message);
});
 });

  function loadBrands(){

$.ajax({
    dataType: "json",
    url: "{{action('CampaignController@getAdvertiser')}}/"+$("#advertiserId").val()
}).done(function(results){
    $("#brandId").empty();

    $.each(results, function(index,value){                          

        var newOption = $("<option value=\""+value.id+"\">"+value.brandName+"</option>");
        $("#brandId").append(newOption);
        // $("#brandId").trigger("chosen:updated");
    }); 
    //$("#brandId").empty();
    // hardcode 1 it must be remove asap
    $.ajax({
        dataType: "json",
        url: "{{action('ReportingController@getCamp')}}/"+1
    }).done(function(results){
        $("#campaignId").empty();
        console.debug(get);
        $(results).each(function(index,value){

            $("#campaignId").append("<option value=\""+value.campaignId+"\">"+value.campaignName+"</option>");
            $('#campaignId').trigger('change'); 
            });
    });
    //loading city
    $.ajax({
        dataType: "json",
        url: "{{action('CampaignLocationController@getLocations')}}/"+1
    }).done(function(results){
        $("#city").empty();

        $(results).each(function(index,value){
             getCityDetails  = value.data[0];

            $("#city").append("<option value=\""+getCityDetails.brandId+"\">"+getCityDetails.city+"</option>");
            $('#city').trigger('change');   
            });
    });

}).fail(function(results){
    alert("Failed to load brands.");
});
 }
 loadBrands();
 $("#advertiserId").change(loadBrands);  
 $("#brandId").change(loadBrands); removed this line now it is working 
$(函数(){ $(“#多选”)。多选({ includeSelectAllOption:true }); $(“#b选择”)。单击(函数(){ 所选变量=$(“#多选选项:已选”); var message=“”; 已选定。每个(函数(){ 消息+=$(this).text()++++“\n”; }); 警报(信息); }); }); 函数loadBrands(){ $.ajax({ 数据类型:“json”, url:“{{action('CampaignController@getAdvertiser“)}}/”+$(“#广告客户ID”).val() }).完成(功能(结果){ $(“#brandId”).empty(); $.each(结果、函数(索引、值){ var newOption=$(“”+value.brandName+“”); $(“#brandId”).append(新选项); //$(“#brandId”).trigger(“已选择:已更新”); }); //$(“#brandId”).empty(); //硬代码1必须尽快将其删除 $.ajax({ 数据类型:“json”, url:“{{action('ReportingController@getCamp')}}/"+1 }).完成(功能(结果){ $(“#活动ID”).empty(); 调试(get); $(结果)。每个(函数(索引、值){ $(“#活动ID”).append(“+value.campaigname+”); $(“#活动ID”).trigger('change'); }); }); //装货城市 $.ajax({ 数据类型:“json”, url:“{{action('CampaignLocationController@getLocations')}}/"+1 }).完成(功能(结果){ $(“#城市”).empty(); $(结果)。每个(函数(索引、值){ getCityDetails=value.data[0]; $(“#city”).append(“+getCityDetails.city+”); $('city')。触发('change'); }); }); }).失败(功能(结果){ 警报(“未能加载品牌”); }); } loadBrands(); $(“#广告客户ID”)。更改(loadBrands); $(“#brandId”).change(loadBrands);已删除此行,现在它正在工作
$(结果)。每个(
用于DOM,您必须使用
$。每个(结果)
INSTADIT仍在做相同的事情,我可以得到我的选项,但仍然给出相同的问题
$(document).ready(function() {
$(function () {
$("#multiselect").multiselect({
    includeSelectAllOption: true
});
$('#btnSelected').click(function () {
    var selected = $("#multiselect option:selected");
    var message = "";
    selected.each(function () {
        message += $(this).text() + " " + "\n";
    });
    alert(message);
});
 });

  function loadBrands(){

$.ajax({
    dataType: "json",
    url: "{{action('CampaignController@getAdvertiser')}}/"+$("#advertiserId").val()
}).done(function(results){
    $("#brandId").empty();

    $.each(results, function(index,value){                          

        var newOption = $("<option value=\""+value.id+"\">"+value.brandName+"</option>");
        $("#brandId").append(newOption);
        // $("#brandId").trigger("chosen:updated");
    }); 
    //$("#brandId").empty();
    // hardcode 1 it must be remove asap
    $.ajax({
        dataType: "json",
        url: "{{action('ReportingController@getCamp')}}/"+1
    }).done(function(results){
        $("#campaignId").empty();
        console.debug(get);
        $(results).each(function(index,value){

            $("#campaignId").append("<option value=\""+value.campaignId+"\">"+value.campaignName+"</option>");
            $('#campaignId').trigger('change'); 
            });
    });
    //loading city
    $.ajax({
        dataType: "json",
        url: "{{action('CampaignLocationController@getLocations')}}/"+1
    }).done(function(results){
        $("#city").empty();

        $(results).each(function(index,value){
             getCityDetails  = value.data[0];

            $("#city").append("<option value=\""+getCityDetails.brandId+"\">"+getCityDetails.city+"</option>");
            $('#city').trigger('change');   
            });
    });

}).fail(function(results){
    alert("Failed to load brands.");
});
 }
 loadBrands();
 $("#advertiserId").change(loadBrands);  
 $("#brandId").change(loadBrands); removed this line now it is working