yii下拉列表 单选按钮用法

下拉列表用法:

<td align="right" class="hui4">企业性质:</td>
<td align="left" class="hui4">
<?php echo CHtml::activeDropDownList($model,'business_nature',
             array('国有'=>'国有',
                '民营'=>'民营',
                '合资'=>'合资',
                '集体'=>'集体',
                '其它'=>'其它',
             )); ?>
</td>

单选按钮用法:

就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','男士'); 

<td align="right" class="hui4">成长阶段:</td>
<td align="left" class="hui4">
<?php
       $stage = CHtml::activeRadioButtonList($model,'stage',array('种子期'=>'种子期','初创期'=>'初创期','成长期'=>'成长期','发展期'=>'发展期','上市筹备期'=>'上市筹备期'));
      $stage= str_replace("<label","<span",$stage);
      $stage= str_replace("</label><br","</span",$stage);
       echo $stage ;?>
</td>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值