zoukankan      html  css  js  c++  java
  • 通过城市联动实时将地址显示到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;
      }
    }
  • 相关阅读:
    Flutter动画(1)动画基础介绍(重要)
    flutter AnimationController动画1
    flutter 动画示例
    Nginx 搭建图片服务器
    dart中list的map方法获取index
    Flutter 视频缩略图
    Flutter:设置字体不随系统字体大小进行改变
    Flutter 屏幕适配flutter_screenutil使用心得
    flutter 软键盘弹起导致定位底部按钮浮动在键盘上的问题
    C++ 代码小技巧(一)
  • 原文地址:https://www.cnblogs.com/l-zl/p/6514580.html
Copyright © 2011-2022 走看看