加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

twitter-bootstrap – 带引导程序3的Yii2复选框组

发布时间:2020-12-17 20:42:21 所属栏目:安全 来源:网络整理
导读:如何在yii2中创建 checkbox group? 这就是我们需要的 div class="btn-group" data-toggle="buttons" label class="btn btn-primary active" input type="checkbox" autocomplete="off" checked Checkbox 1 (pre-checked) /label label class="btn btn-prima
如何在yii2中创建 checkbox group?

enter image description here

这就是我们需要的

<div class="btn-group" data-toggle="buttons">
  <label class="btn btn-primary active">
    <input type="checkbox" autocomplete="off" checked> Checkbox 1 (pre-checked)
  </label>
  <label class="btn btn-primary">
    <input type="checkbox" autocomplete="off"> Checkbox 2
  </label>
  <label class="btn btn-primary">
    <input type="checkbox" autocomplete="off"> Checkbox 3
  </label>
</div>

这就是我所拥有的

<?
    $options = ['uncheck'=>0];

    echo ButtonGroup::widget([
        'options' => [
            'data-toggle' => 'buttons'
        ],'buttons' => [
            $form->field($model,'field1')->checkbox($options),$form->field($model,'field2')->checkbox($options),'field3')->checkbox($options),],]);
?>

我需要在代码中添加什么来生成降价?

解决方法

我的变种.我使用标准的yii radiobox并自定义模板.

<?= $form->field($model,'attribute')->radioList(
[
        1 => 'Enabled',2 => 'Disabled'
    ],[
        'item' => function ($index,$label,$name,$checked,$value) {
            if ($value==1)
                $class_btn =  'btn-success'; // Style for enable
            else
                $class_btn = 'btn-default'; // Style for disable

            if ($checked)
                $class_btn = $class_btn.' active'; // Style for checked button
            return
                '<label class="btn '. $class_btn.'">' . Html::radio($name,['value' => $value]) . $label . '</label>';
        },'class' => 'btn-group',"data-toggle"=>"buttons",// Bootstrap class for Button Group
    ]
)->label('Some label');
?>

My result

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读