php教程|php手册
yii,级联,下拉菜单
php教程-php手册
微信场景应用 源码,ubuntu套接字编程,爬虫下载豆瓣文件,php怎么加加入PHP,seo好加盟lzw
这篇文章主要介绍了yii实现级联下拉菜单的方法,需要的朋友可以参考下
md5加密算法 java源码,vscode常用编辑快捷键,班图精神ubuntu,怎么让tomcat运行,爬虫代码图,php二维数组分页,seo是补量的意思么lzw
交易站源码,vscode设置自动编译,ubuntu桌面死机,安装2个tomcat,资料爬虫,php url 参数解析,电话seo优化专业服务,足球平台网站源码,微擎插件模板消息lzw
本文详细讲述了yii实现级联下拉菜单的方法,具体步骤如下:
1.模版中加入如下代码:
dropDownList($model, ‘src_type_id’, OrderSrc::options(), array(
‘id’ => ‘task-order-src-id’,
));
echo $form->dropDownList($model, ‘src_shop_id’, array(”=>’全部’), array(
‘id’ => ‘task-shop-id’,
))
?>
在这段代码中,OrderSrc_options() 这个是先读取一个下拉菜单。调用OrderScr model中的options方法。内容如下
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代码,,实现当第一个下拉菜单变化时给第二个下拉菜单进行内容赋值。
$().ready(function(e) { $(‘#task-order-src-id’).change(function(e) { refreshShops(); }); refreshShops(); function refreshShops() { $.get(‘createUrl(‘getShops’)?>’, { ‘srcId’: $(‘#task-order-src-id’).val() }, function(html_content) { $(‘#task-shop-id’) .html(html_content) .find(‘option[value=src_shop_id?>]’).attr(‘selected’, ‘selected’); }); }});
在这段JS代码中,实现调取一个程序获取第二个下拉菜单的值(调用Controller中的actionGetShops方法),任何追加到第二个下拉菜单中。
Controller中的actionGetShops方法如下:
public function actionGetShops() {
$srcId = $_GET[‘srcId’];
$array = ThirdpartInterfaceConfig::options($srcId);
$htmlContent = “全部”;
foreach($array as $k=>$v) {
$htmlContent .= “{$v}”;
}
echo $htmlContent;
}