• 通过城市联动实时将地址显示到text中


    <div class="form-group field-supplier-sort <?php if($model->getErrors('province_id') || $model->getErrors('city_id') || $model->getErrors('district_id')):?>has-error<?php else:?>has-success<?php endif;?>">
        <label class="control-label col-sm-2" for="supplier-sort">配电室所在地区</label>
        <div class="col-sm-10">
            <div class="form-inline citylist">
                <?=Html::activeDropDownList($model, 'province_id', ArrayHelper::merge([0=>'请选择省份'], Area::getArrayForInput(0)), ['class'=>'input-sm form-control', 'tabindex'=>5]);?>
                <?=Html::activeDropDownList($model, 'city_id', ArrayHelper::merge([0=>'请选择城市'], Area::getArrayForInput($model->province_id)), ['class'=>'input-sm form-control', 'tabindex'=>5])?>
                <?=Html::activeDropDownList($model, 'district_id', ArrayHelper::merge([0=>'请选择区域'], Area::getArrayForInput($model->city_id)), ['class'=>'input-sm form-control', 'tabindex'=>5])?>
            </div>
            <div class="help-block help-block-error "><?=$model->getFirstError('province_id') . $model->getFirstError('city_id') . $model->getFirstError('district_id')?></div>
        </div>
    </div>
    <div class="form-group field-concentrator-voltage has-success">
        <label class="control-label col-sm-2" for="concentrator-voltage">地址</label>
        <div class="col-sm-2">
            <input type="text" id="concentrator-address" class="form-control input-sm cityName" name="Concentrator[address]" value="<?=$model->address;?>" >
            <div class="help-block help-block-error "></div>
        </div>
    </div>
    <input type="text" id="alladdress" class="form-control input-sm" name="Concentrator[add]" value="<?=$model->addressText?>">
    <script type="text/javascript">
        function getcitytext(){//城市联动实时显示
            citytext = '';
            $(".citylist select").each(function(){
                if($(this).val()>0){
                    citytext += $(this).find('option:selected').text();
                }else{
                    citytext += '';
                }
            });
            $("#alladdress").val(citytext);
        }
        $(function(){
            getcitytext();
            $('#concentrator-province_id').change(function(){
                var parent_id = parseInt($(this).val());
                $.post('<?=Url::to(['/ajax/areaoption'])?>', {parent_id:parent_id, d:'请选择城市'}, function(data){
                    if(data) {
                        $('#concentrator-city_id').html(data);
                        $('#concentrator-district_id').html('<option>请选择区域</option>');
                        getcitytext();
                    }
                });
            });
            $('#concentrator-city_id').change(function(){
                var parent_id = parseInt($(this).val());
                $.post('<?=Url::to(['/ajax/areaoption'])?>', {parent_id:parent_id, d:'请选择区域'}, function(data){
                    if(data) {
                        $('#concentrator-district_id').html(data);
                        getcitytext();
                    }
                });
            });
            $(document).on("change", "#concentrator-district_id", function () {
                getcitytext();
            });
        });
    </script>
    
    class AjaxController extends Controller {
      public function actionAreaoption(){
         $parentId = intval($_POST['parent_id']);
         $default = $_POST['d'];
         $html = '';
         if ($default) {
            $html .= '<option value="0">' . $default . '</option>';
         }
         if ($parentId > 0) {
         $array = Area::getArrayForInput($parentId);
         foreach ($array as $key=>$value) {
            $html .= '<option value="' . $key . '">' . $value . '</option>';
         }
         }
         echo $html;
      }
    }
  • 相关阅读:
    Nginx URL后面不加斜杠301重定向
    Jenkins 配置 Node.js 项目
    在 Linux 上搭建IntelliJ IDEA license server服务器
    Vue 使用细节收集
    sinopia 搭建记录
    cli 开发记录
    Cgroup(一)简介
    Kubernetes (一)POD驱逐
    RabbitMQ(五)镜像队列
    RabbitMQ(四)队列结构
  • 原文地址:https://www.cnblogs.com/l-zl/p/6514580.html
Copyright © 2020-2023  润新知