原文:http://www.yiichina.com/code/636

<?php
use yii\helpers\Url;
use yii\widgets\ActiveForm;
use yii\helpers\ArrayHelper;
use yii\helpers\Html; /* @var $this yii\web\View */
/* @var $model common\search\service\ItemSearch */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="row">
<div class="item-search">
<?php $form = ActiveForm::begin([
'action' => ['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, 'id', 'name'), ['prompt' => '请选择区县'])->label('请选择区县', ['class' => 'sr-only']) ?> <?= $form->field($model, 'communityName', ['options' => ['class' => 'form-group col-lg-2']])->dropDownList(ArrayHelper::map($communities, 'id', 'name'), ['prompt' => '请选择小区'])->label('请选择小区', ['class' => 'sr-only']) ?> <div class="col-lg-2 col-lg-offset-1">
<input class="form-control" id="keyword" placeholder="请输入小区名" value="" />
</div>
<div class="col-lg-1">
<button type="button" id="search-community" class="btn btn-info">搜索</button>
</div>
<p></p> <div class="form-group col-lg-1 pull-right">
<?= Html::submitButton('搜索', ['class' => 'btn btn-primary']) ?>
</div> <?php ActiveForm::end(); ?>
</div>
</div>
<p>&nbsp;</p>
<?php
$this->registerJs('
//市地址改变
$("#itemsearch-cityname").change(function() {
//市id值
var cityid = $(this).val();
$("#itemsearch-areaname").html("<option value=\"0\">请选择区县</option>");
$("#itemsearch-communityname").html("<option value=\"0\">请选择小区</option>");
if (cityid > 0) {
getArea(cityid);
}
}); //区地址改变
$("#itemsearch-areaname").change(function() {
//区id值
var areaid = $(this).val();
$("#itemsearch-communityname").html("<option value=\"0\">请选择小区</option>");
if (areaid > 0) {
getCommunity(areaid);
}
}); //获取市下面的区列表
function getArea(id)
{
var href = "' . Url::to(['/service/base/get-area-list'], true). '"; $.ajax({
"type" : "GET",
"url" : href,
"data" : {id : id},
success : function(d) {
$("#itemsearch-areaname").append(d);
}
});
} //获取区下面的小区列表
function getCommunity(id)
{
var href = "' . Url::to(['/service/base/get-community-list'], true) . '";
$.ajax({
"type" : "GET",
"url" : href,
"data" : {id : id},
success : function(d) {
$("#itemsearch-communityname").append(d);
}
});
} //搜索小区
$("#search-community").click(function() {
var word = $("#keyword").val();
var areaid = $("#itemsearch-areaname option:selected").val();
var href = "' . Url::to(['/service/base/search-community'], true) . '"; if (areaid > 0) {
$.ajax({
"type" : "GET",
"url" : href,
"data" : {id : areaid, word : word},
success : function(d) {
$("#itemsearch-communityname").html(d);
}
});
}
});
');
?>
<?php
use yii\helpers\Url;
use yii\widgets\ActiveForm;
use yii\helpers\ArrayHelper;
use yii\helpers\Html; /* @var $this yii\web\View */
/* @var $model common\search\service\ItemSearch */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="row">
<div class="item-search">
<?php $form = ActiveForm::begin([
'action' => ['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, 'id', 'name'), ['prompt' => '请选择区县'])->label('请选择区县', ['class' => 'sr-only']) ?> <?= $form->field($model, 'communityName', ['options' => ['class' => 'form-group col-lg-2']])->dropDownList(ArrayHelper::map($communities, 'id', 'name'), ['prompt' => '请选择小区'])->label('请选择小区', ['class' => 'sr-only']) ?> <div class="col-lg-2 col-lg-offset-1">
<input class="form-control" id="keyword" placeholder="请输入小区名" value="" />
</div>
<div class="col-lg-1">
<button type="button" id="search-community" class="btn btn-info">搜索</button>
</div>
<p></p> <div class="form-group col-lg-1 pull-right">
<?= Html::submitButton('搜索', ['class' => 'btn btn-primary']) ?>
</div> <?php ActiveForm::end(); ?>
</div>
</div>
<p>&nbsp;</p>
<?php
$this->registerJs('
//市地址改变
$("#itemsearch-cityname").change(function() {
//市id值
var cityid = $(this).val();
$("#itemsearch-areaname").html("<option value=\"0\">请选择区县</option>");
$("#itemsearch-communityname").html("<option value=\"0\">请选择小区</option>");
if (cityid > 0) {
getArea(cityid);
}
}); //区地址改变
$("#itemsearch-areaname").change(function() {
//区id值
var areaid = $(this).val();
$("#itemsearch-communityname").html("<option value=\"0\">请选择小区</option>");
if (areaid > 0) {
getCommunity(areaid);
}
}); //获取市下面的区列表
function getArea(id)
{
var href = "' . Url::to(['/service/base/get-area-list'], true). '"; $.ajax({
"type" : "GET",
"url" : href,
"data" : {id : id},
success : function(d) {
$("#itemsearch-areaname").append(d);
}
});
} //获取区下面的小区列表
function getCommunity(id)
{
var href = "' . Url::to(['/service/base/get-community-list'], true) . '";
$.ajax({
"type" : "GET",
"url" : href,
"data" : {id : id},
success : function(d) {
$("#itemsearch-communityname").append(d);
}
});
} //搜索小区
$("#search-community").click(function() {
var word = $("#keyword").val();
var areaid = $("#itemsearch-areaname option:selected").val();
var href = "' . Url::to(['/service/base/search-community'], true) . '"; if (areaid > 0) {
$.ajax({
"type" : "GET",
"url" : href,
"data" : {id : areaid, word : word},
success : function(d) {
$("#itemsearch-communityname").html(d);
}
});
}
});
');
?>

使用Yii2中dropdownlist实现地区三级联动的例子的更多相关文章

  1. 非常不错的地区三级联动,js简单易懂。封装起来了

    首先需要引入area.js,然后配置并初始化插件: 例: <!-- 绑定银行卡开始 --> <script src="js/area.js"></sc ...

  2. 20150303--从SQL中获取数据的三级联动

    省市地区的三级联动,每变更一次所选地都需要提交,但是又不需要把整个页面提交,所以我们需要使用控件:UdataPanel.工具--AJAX扩展 还有ScriptManager,并要将其放在页面的最顶端. ...

  3. angular实现地区三级联动

    <!DOCTYPE html><html ng-app="myapp"> <head> <meta charset="UTF-8 ...

  4. ajax+struts2 实现省份-城市-地区三级联动

    1.需求分析 2.js部分(通过ajax异步请求实现) 省份-->城市联动 城市-->地区 3.struts部分 struts.xml action部分 4.service部分 5.总结 ...

  5. PHP+AJAX 地区三级联动代码

    <html><head><meta http-equiv="Content-Type" content="text/html; charse ...

  6. 【2017-05-05】timer控件、三级联动、帐号激活权限设置

    一.Timer控件 Timer实际就是一个线程控件. 属性:Enabled    是否被启用 Interval     多长时间执行一次控件中的代码 事件: Tick     事件中放要执行的代码. ...

  7. timer控件、三级联动、帐号激活权限设置

    一.Timer控件 Timer实际就是一个线程控件. 属性:Enabled    是否被启用 Interval     多长时间执行一次控件中的代码 事件: Tick     事件中放要执行的代码. ...

  8. 微信小程序 实现三级联动-省市区

    github项目地址   https://github.com/z1511676208/chooseAddr 序:项目中需要用到三级联动,自己试着写了下,也查了一些资料,现在把这个记录一下,里面地区数 ...

  9. vue移动端地址三级联动组件(一)

    vue移动端地区三级联动 省,市,县.用的vue+mintUi 因为多级联动以及地区的规则比较多.正好有时间自己写了一个.有问题以及建议欢迎指出.涉及到dom移动,所以依赖vue+jquery.这边数 ...

随机推荐

  1. fanqiang_bak

  2. php -- realpath($path) 函数

    PHP realpath路径函数会检测$path指向的目标文件(或文件夹)是否真实存在,相当于调用了file_exists($path). 1.如果目标文件存在且不是符号连接(linux下俗称“软链接 ...

  3. 奇葩问题:ListView中Item与Item中的Button不能单击问题

    android中ListView是一个经常要用到的一个组件,用到该组件时经常会碰到ListView的Item和Item中的Button不能单击的问题. 本人在使用时同样也遇到过这样的情况,共有三种情况 ...

  4. iOS private-api-checker私有API检测

    转自: http://www.jianshu.com/p/07779e293ca7 注:  '根目录' 指的是 private-api-checker 包的目录 iOS-private-api-che ...

  5. Sharepoint 2013 Workflow Error

    问题: (1)提示“reload the page and then start the workflow”错误 (2)提示“Unable to properly communicate with t ...

  6. DOTween中的Time.Scale

    因为在做游戏暂停的时候通常会使用Time.Scale = 0 ,可是暂停的时候UI如果需要继续有动画怎么办呢?在DoTween中只需要设置         tweener.SetUpdate(true ...

  7. MySQL Server 5.7.13

    如何安装MySQL,MySQL两种安装方式_百度经验 http://jingyan.baidu.com/article/cd4c2979033a17756f6e6047.html "C:\P ...

  8. php-fpm配置文件,指定session保存目录

    cd  /etc/php-fpm.d 目录下 cat www.conf文件 修改user ,group 指定session 保存路径 www.conf日志配置路径 php-fpm.conf

  9. hdu 5038 水题 可是题意坑

    http://acm.hdu.edu.cn/showproblem.php?pid=5038 就是求个众数  这个范围小 所以一个数组存是否存在的状态即可了 可是这句话真恶心  If not all ...

  10. python2.0 s12 day3

    s12 day3 视频每节的内容 03 python s12 day3 本节内容概要 第三天的主要内容 上节没讲完的: 6.集合 7.collections 1)计数器 2)有序字典 3)默认字典 4 ...