zoukankan      html  css  js  c++  java
  • yii2.0 表单小部件常用的默认选中

    下面自己总结了一下表单小部件中经常使用到的一些默认选中

    直接在视图代码里面说明啦

    <?php
    
    //这个表头就不多说了
    
    use yiihelpersHtml;
    use yiiwidgetsActiveForm;
    
    
    $form = ActiveForm::begin([
        'id'        => 'exam-form',
        'options'   => ['class' => 'form-horizontal','enctype'=>'multipart/form-data'],
        'action'    =>'?r=task/add',
        'method'    =>  'post',
    ]);
    ?>
    
    
    
    
    文本框的默认选中:
    <?  $model->username = '我是猪'?>            
    <?= $form->field($model,'username')->textInput(/*['value'=>'我是猪']*/)?><!--第二种用value-->
    
    
    <?= $form->field($model,'pwd')->passwordInput()?>
    
    单选框的默认选中:
    <?  $model->sex = '1'?>           //value为1的将为默认选中          
    <?= $form->field($model,'sex')->radioList(['0'=>'男','1'=>'女'])?>
    
    多选框的默认选中:(应该也能看的出来原理)
    <?  $model->hobby = ['iphone','sanxing' ] ?>
    <?= $form->field($model,'hobby')->checkboxList(['sanxing'=>'三星','iphone'=>'苹果','vivo'=>'步步高'])?>
    
    下来菜单的默认选中:
    <?  $model->news_classify = 3?>        //value为3的将为默认选中    
    <?= $form->field($model,'news_classify')->dropDownList($arr)?>
    
    <div class=”form-group”>
        <div class=”col-lg-offset-1 col-lg-11″>
            <?= Html::submitButton('添加', ['class' => 'btn btn-primary']) ?>
        </div>
    </div>
    <?php ActiveForm::end() ?>
    
    以上就是常用的标签默认选中,临时写的,有什么不太对的,我会在评论补充。
    
  • 相关阅读:
    python中xrange和range的异同
    Python:使用threading模块实现多线程编程
    python Queue模块
    Python中pass语句的作用
    Python的作用域
    eclipse颜色配置
    protobuf
    python调试总结
    chardet安装
    Windows下搭建PHP开发环境
  • 原文地址:https://www.cnblogs.com/aini521521/p/6994058.html
Copyright © 2011-2022 走看看