Yii2使用dropdownlist实现地区三级联动功能的方法
前端之家收集整理的这篇文章主要介绍了
Yii2使用dropdownlist实现地区三级联动功能的方法,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
本文实例讲述了Yii2使用dropdownlist实现地区三级联动功能的方法。分享给大家供大家参考,具体如下:@H_403_1@
视图部分:@H_403_1@
PHP;">
['index'],'method' => 'get','options' => ['class' => 'form-inline']
]); ?>
= $form->field($model,'cityName',['options' => ['class' => 'form-group col-lg-2']])->dropDownList(ArrayHelper::map($cities,'id','name'),['prompt' => '请选择城市'])->label('请选择城市',['class' => 'sr-only']) ?>
= $form->field($model,'areaName',['options' => ['class' => 'form-group col-lg-2']])->dropDownList(ArrayHelper::map($areas,['prompt' => '请选择区县'])->label('请选择区县','communityName',['options' => ['class' => 'form-group col-lg-2']])->dropDownList(ArrayHelper::map($communities,['prompt' => '请选择小区'])->label('请选择小区',['class' => 'sr-only']) ?>
@H_403_1@
'btn btn-primary']) ?>
@H_403_1@
registerJs('
//市地址改变
$("#itemsearch-cityname").change(function() {
//市id值
var cityid = $(this).val();
$("#itemsearch-areaname").html("
模型部分:@H_403_1@
就是我们常用的ajax请求,当然PHP中需要直接组合成