yii框架中的CHtml::activeRadioButtonList生成的单选框禁止换行的方法
最近在用yii框架开发一个项目,发现这个项目非常强大,而且非常的容易上手,建议php爱好者去学习一下。
用的时候遇到一个问题,就CHtml::activeRadioButtonList生成的单选框总是分成两行,看起来很舒服,后来去看了一下他的源码,发现他默认输出的是带有label标签的,我个人是把这个label标签换成span标签。
使用方法:
$sex_radiobuttonList = CHtml::activeRadioButtonList($model,'sex',array('男士'=>'男士','女士'=>'女士'),
array('template'=>'{input}{label}','separator'=>" "));
$sex_radiobuttonList= str_replace("<label", "<span", $sex_radiobuttonList);
$sex_radiobuttonList= str_replace("</label", "</span", $sex_radiobuttonList);
echo $sex_radiobuttonList;
另外,设置首选值也很扁的就可以解决了,在Controller中加入一句话
$model->setAttribute('sex','男士');
posted on 2010-01-16 02:52 lonelybyte 阅读(1241) 评论(1) 编辑 收藏 举报