Yii2自定义checkboxList和radioList样式

2022年05月22日 阅读368次 分类:开发 标签:phpyii2微码经验

版权声明:本文为博主原创或转载自网络,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。

本文链接:http://www.zhuyanjun.cn/development/1888.html

在Yii 2.0里面, 怎样自定义checkboxList和radioList样式:

// 输出bootstrap单行样式的radio
<?=$form->field($fieldModel, 'is_show_list')->radioList([1=>'是',0=>'否'],['itemOptions'=>['labelOptions'=>['class'=>'radio-inline']]]); ?>

// 输出bootstrap多行样式的radio
<?=$form->field($model, 'is_show_list')->radioList([1=>'是',0=>'否'],['item'=>function($index, $label, $name, $checked, $value){
    return '<div class="radio"><label>'. '<input type="radio" name="'.$name.'" value="'.$value.'" '.($checked?"checked":"").'>'.ucwords($label).'</label></div>';
}]); ?>

// 输出bootstrap单行样式的checkbox
<?=$form->field($fieldModel, 'is_show_list')->checkboxList([0=>'红',1=>'黑',2=>'黄'],['itemOptions'=>['labelOptions'=>['class'=>'checkbox-inline']]]); ?>

// 输出bootstrap多行样式的checkbox
<?=$form->field($model, 'like')->checkboxList([0=>'红',1=>'黑',2=>'黄'],['item'=>function($index, $label, $name, $checked, $value){
    return '<div class="radio"><label>'. '<input type="checkbox" name="'.$name.'" value="'.$value.'" '.($checked?"checked":"").'>'.ucwords($label).'</label></div>';
}]); ?>


关联文章

(本篇完)

是不是学到了很多?可以

版权声明:本文为博主原创或转载自网络,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。

本文链接:http://www.zhuyanjun.cn/development/1888.html