• 省市区联动


    html部分

     <tr>
                <th class="textalign">所在城市</th>
                <td>
                    <select name="province_id" class="select">
                        <?php if ($order->province_id): ?>
                        <option value="<?=$order->province_id?>"><?=$order->strProvinceName()?></option>
                        <?php else: ?>
                        <option value="">请选择</option>
                        <?php endif; ?>
                          <?php if(isset($province) && count($province)):?>
                          <?php foreach ($province as $key=>$val):?>
                          <option value="<?=$key?>"><?=$val?></option>
                          <?php endforeach;?>
                          <?php endif;?>
                    </select>
                    <select name="city_id" class="select">
                        <?php if($order->city_id): ?>
                        <option value="<?=$order->city_id?>"><?=$order->strCityName()?></option>
                        <?php else: ?>
                        <option value="">请选择</option>
                        <?php endif; ?>
                    </select>
                    <select name="country_id" class="select">
                        <?php if($order->country_id): ?>
                        <option value="<?=$order->country_id?>"><?=$order->strCountryName()?></option>
                        <?php else: ?>
                        <option value="">请选择</option>
                        <?php endif; ?>
                      </select>
                </td>
            </tr>

    js部分代码

       $('select[name="province_id"]').change(function(){
                  $.get('<?=url('city/city')?>', {'province_id':$(this).val()}, function(data){
                      if(data.length===0){
                          alert('未查找到下属城市');
                          return;
                      }
                      $('select[name="city_id"]').empty();
                      $('select[name="city_id"]').append("<option value='0'>请选择省</option>");
                      for (var i in data){
                          $('select[name="city_id"]').append('<option value="'+data[i].id+'">'+data[i].name+'</option>');
                      }
                  });
              });
              $('select[name="city_id"]').change(function(){
                  $.get('<?=url('city/country')?>', {'city_id':$(this).val()}, function(data){
                      if(data.length===0){
                          alert('未查找到下属城市');
                          return;
                      }
                       $('select[name="country_id"]').empty();
                      $('select[name="country_id"]').append("<option value='0'>请选择省</option>");
                      for (var i in data){
                          $('select[name="country_id"]').append('<option value="'+data[i].id+'">'+data[i].name+'</option>');
                      }
                  });
              });
  • 相关阅读:
    pyecharts学习
    反爬
    pandas
    用 pymongo 操作 MongoDB 数据库
    数据库隔离级别---读未提交,读已提交,重复读,序列化
    vscode 配置c++和python编译和调试环境
    sublime Text3 配置c++编译环境并设置快捷键
    GIT学习笔记
    redis单节点部署
    二元多项式求逆中的小坑
  • 原文地址:https://www.cnblogs.com/wicub/p/4891189.html
Copyright © 2020-2023  润新知