• 通过城市联动实时将地址显示到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;
      }
    }
  • 相关阅读:
    hdu 1086 You can Solve a Geometry Problem too 求n条直线交点的个数
    2019 上半年 南昌网络赛
    第十章 存储过程和函数
    第九章 Mysql函数
    第八章 Mysql运算符
    第七章 插入、更新与删除数据
    第六章 查询数据
    第五章 触发器
    第四章 视图
    第三章 索引
  • 原文地址:https://www.cnblogs.com/l-zl/p/6514580.html
Copyright © 2020-2023  润新知