其他分享
首页 > 其他分享> > 省市县三级联动

省市县三级联动

作者:互联网

                           <div >
                              <label for="user-email" class="am-form-label">收货人地址</label>
                              <div class="am-form-content">
                                  <select name="" id="province" style="width: 200px">
                                      <option class="am-form-label">请选择省</option>
                                      @foreach($sheng as $sh)
                                      <option class="am-form-label" value="{{$sh->id}}">{{$sh->area}}</option>
                                      @endforeach
                                  </select>
<select name="" id="city" style="width: 200px"> <option class="am-form-label" value="{{$sh->id}}">请选择市</option> </select>
<select name="" id="county" style="width: 200px"> <option class="am-form-label">请选择县</option> </select> </div> </div>
 //省市县
<script>
$("#province").change(function (){
var id = $(this).val();
getcity("#city",id,"请选择市")
})
$("#city").change(function (){
var id = $(this).val();
getcity("#county",id,"请选择县")
})

//写一个公共函数
function getcity(a,id,city){
$.get("{{url('Index/shi')}}",{id:id},function (data){
var str ="<option class='am-form-label'>"+city+"</option>";
for(var i=0;i<data.length ;i++){
str += "<option class='am-form-label' value='"+data[i].id+"'>"+data[i].area+"</option>";
}
$(a).html(str)
},"json")
}
</script>




 

 

标签:function,city,省市,getcity,str,联动,var,id,三级
来源: https://www.cnblogs.com/junwuxiao/p/16029364.html