无为清净楼资源网 Design By www.qnjia.com

本文详细讲述了yii实现级联下拉菜单的方法,具体步骤如下:

1.模版中加入如下代码:

<"white-space:pre"> </span>'id' => 'task-order-src-id',
 ));
 echo $form->dropDownList($model, 'src_shop_id', array(''=>'全部'), array(
 <span style="white-space:pre"> </span>'id' => 'task-shop-id',
 ))
"htmlcode">
public static function options($hasShop = true) {
 $model = new self();
 if($hasShop) $model->hasShop();
 $models = $model->findAll();
 $array = array(''=>'全部');
 foreach($models as $model) {
 $array[$model->src_id] = $model->src_name;
 }
 return $array;
}

2.然后在模版页面中增加JS代码,实现当第一个下拉菜单变化时给第二个下拉菜单进行内容赋值。

<script type='text/javascript'>
$().ready(function(e) {
 $('#task-order-src-id').change(function(e) {
 refreshShops();
 });
 refreshShops();
 function refreshShops() {
 $.get('<"htmlcode">
public function actionGetShops() {
 $srcId = $_GET['srcId'];
 $array = ThirdpartInterfaceConfig::options($srcId);
 $htmlContent = "<option value=''>全部</options>";
 foreach($array as $k=>$v) {
 $htmlContent .= "<option value='{$k}'>{$v}</option>";
 }
 echo $htmlContent;
}
标签:
yii,级联,下拉菜单

无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com