yii实现级联下拉菜单的方法
(编辑:jimmy 日期: 2025/10/27 浏览:3 次 )
本文详细讲述了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中assets的使用示例