如何克隆ajax下拉列表

时间:2018-06-10 16:17:44

标签: javascript

我有一个下拉框,根据我从另一个下拉菜单中选择的选项填充了ajax。我需要复制下拉框,保持通过ajax加载相同的选项,这是我迄今为止所做的。非常感谢您的帮助

这是从第一个dropbox获取tha值然后将其用于ajax

的代码
$('#flatGroup').on('change',function(){
        var countryID = $(this).val();
        console.log(countryID);
        if(countryID){
            $.ajax({
                type:'POST',
                url:'../controllers/ctrl_admin_group_table_app/ctrl_admin_get_building_table.php',
                data: {

                  group_id: countryID

                },

                success:function(html){
                    $('#flatTable-1').html(html);
                    $(".bs-select").selectpicker('refresh');

                }
            }); 
        }

    });

这是我用来关闭从ajax接收选项的第二个dropbox的代码

// start repeating form tabelle
        //Start repeating form group add limit
        var maxGroup1 = 5;
        //add more fields group
        var fieldGroup1= $(".fieldGroup1").clone();

        $(".addMore1").click(function() {

          var fgc1 = $('body').find('.fieldGroup1').length;

          if (fgc1 < maxGroup1) {

            var fieldHTML1 = '<div class="form-group fieldGroup1">' + fieldGroup1.html() + '<div class="col-md-1"><label class="control-label">&nbsp;</label><a href="#" data-repeater-delete class="btn btn-danger remove"><i class="fa fa-close"></i></a></div></div>';

            fieldHTML1 = fieldHTML1.replace('flatTable-1', 'flatTable-' + (fgc1 + 1));
            fieldHTML1 = fieldHTML1.replace('flatMillesimi-1', 'flatMillesimi-' + (fgc1 + 1));

            $('body').find('.fieldGroup1:last').after(fieldHTML1);

            $('.bs-select').selectpicker({

              iconBase: 'fa',
              tickIcon: 'fa-check'
            });

          } else {

            swal("Operazione Annullata", "Hai raggiunto il massimo numero di proprietari registrabili", "error");

          }
        });

        //remove fields group
        $("body").on("click", ".remove", function() {
          $(this).parents(".fieldGroup1").remove();
        });
        // end repeating form

这是HTML代码

  <div class="row">

        <div class="col-md-9">

                <div class="portlet-body form">

                            <div class="col-md-9">
                                <div class="mt-repeater">
                                    <div data-repeater-list="group-b">
                                        <div data-repeater-item class="row">

                                          <div class="form-group fieldGroup1">

                                            <div class="col-md-4">

                                              <div class="form-group">
                                                <label class="control-label">Tabella</label>

                                                <select class="form-control bs-select" id="flatTable-1" name="flatTable[]" title="Seleziona tabella millesimale"></select>

                                              </div>

                                            </div>

                                            <div class="col-md-4">

                                              <div class="form-group">
                                                <label class="control-label">
                                                  <i class="fa fa-info-circle red tooltips" data-placement="top" data-original-title="Quota del titolare dell'immobile" ></i>Millessimi<span class="required"> * </span>
                                                </label>
                                                   <input type="text" id="flatMillesimi-1" name="flatMillesimi[]" class="form-control" placeholder="Millessimi dell'immobile" >
                                                </div>

                                            </div>

                                          </div> <!--  Fine field group -->

                                        </div>
                                    </div>

                                 <!--    <hr> -->
                                      <a href="javascript:;" data-repeater-create class="btn btn-info mt-repeater-add addMore1">
                                          <i class="fa fa-plus"></i> Aggiungi tabella</a>
                                      <br>
                                      <br>

                                  </div>
                            </div>
                </div>

        </div>
    </div>

0 个答案:

没有答案