<i id='mCxnZ'><tr id='mCxnZ'><dt id='mCxnZ'><q id='mCxnZ'><span id='mCxnZ'><b id='mCxnZ'><form id='mCxnZ'><ins id='mCxnZ'></ins><ul id='mCxnZ'></ul><sub id='mCxnZ'></sub></form><legend id='mCxnZ'></legend><bdo id='mCxnZ'><pre id='mCxnZ'><center id='mCxnZ'></center></pre></bdo></b><th id='mCxnZ'></th></span></q></dt></tr></i><div id='mCxnZ'><tfoot id='mCxnZ'></tfoot><dl id='mCxnZ'><fieldset id='mCxnZ'></fieldset></dl></div>

    <tfoot id='mCxnZ'></tfoot>
    <legend id='mCxnZ'><style id='mCxnZ'><dir id='mCxnZ'><q id='mCxnZ'></q></dir></style></legend>

    <small id='mCxnZ'></small><noframes id='mCxnZ'>

    • <bdo id='mCxnZ'></bdo><ul id='mCxnZ'></ul>

        yii2:使复选框被选中

        时间:2023-09-24

            • <bdo id='raMdl'></bdo><ul id='raMdl'></ul>

              1. <legend id='raMdl'><style id='raMdl'><dir id='raMdl'><q id='raMdl'></q></dir></style></legend><tfoot id='raMdl'></tfoot>
                    <tbody id='raMdl'></tbody>
                • <small id='raMdl'></small><noframes id='raMdl'>

                • <i id='raMdl'><tr id='raMdl'><dt id='raMdl'><q id='raMdl'><span id='raMdl'><b id='raMdl'><form id='raMdl'><ins id='raMdl'></ins><ul id='raMdl'></ul><sub id='raMdl'></sub></form><legend id='raMdl'></legend><bdo id='raMdl'><pre id='raMdl'><center id='raMdl'></center></pre></bdo></b><th id='raMdl'></th></span></q></dt></tr></i><div id='raMdl'><tfoot id='raMdl'></tfoot><dl id='raMdl'><fieldset id='raMdl'></fieldset></dl></div>

                • 本文介绍了yii2:使复选框被选中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用 Yii2 框架,我想生成这样的 html 代码

                  在使用 ActiveForm 的视图中.

                  我试过了

                  echo $form->field($model, 'order')->checkBox(['label' => ..., 'uncheck' => null, 'checked' => true]);

                  以及

                  echo $form->field($model, 'order')->checkBox(['label' => ..., 'uncheck' => null, 'checked' => 'checked']);

                  但是生成的 html 代码中没有出现所需的字符串checked".

                  奇怪的是,如果我用selected"代替checked"

                  echo $form->field($model, 'order')->checkBox(['label' => ..., 'uncheck' => null, 'selected' => true]);

                  然后生成的html代码包含属性selected":

                  那么,如何为属性为checked"的复选框生成 html 代码?

                  解决方案

                  我猜这个复选框只有在 $model->order 属性取 true 值时才会被选中如果它有 false(0nullfalse 等)值 - 字段将不被选中.

                  I am using Yii2 framework and I'd like to generate an html code like this

                  <input type="checkbox" id="queue-order" name="Queue[order]" value="1" checked>
                  

                  in a view which uses ActiveForm.

                  I've tried

                  echo $form->field($model, 'order')
                            ->checkBox(['label' => ..., 'uncheck' => null, 'checked' => true]); 
                  

                  as well as

                  echo $form->field($model, 'order')
                            ->checkBox(['label' => ..., 'uncheck' => null, 'checked' => 'checked']); 
                  

                  but desired string "checked" does not appear in the generated html code.

                  Strangely enough, if I substitute "checked" with "selected"

                  echo $form->field($model, 'order')
                            ->checkBox(['label' => ..., 'uncheck' => null, 'selected' => true]); 
                  

                  then generated html code contains attribute "selected":

                  <input type="checkbox" id="queue-order" name="Queue[order]" value="1" selected>
                  

                  So, how can I generate html code for a checkbox with attribute "checked"?

                  解决方案

                  I guess this checkbox will be checked only if $model->order property take true value and if it has false (0 or null or false etc) value - field will be unchecked.

                  这篇关于yii2:使复选框被选中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Yii 对重载属性的间接修改 下一篇:Yii 中的更新查询

                  相关文章

                  <tfoot id='jdYJJ'></tfoot>

                  <small id='jdYJJ'></small><noframes id='jdYJJ'>

                    <legend id='jdYJJ'><style id='jdYJJ'><dir id='jdYJJ'><q id='jdYJJ'></q></dir></style></legend>
                      <bdo id='jdYJJ'></bdo><ul id='jdYJJ'></ul>

                    1. <i id='jdYJJ'><tr id='jdYJJ'><dt id='jdYJJ'><q id='jdYJJ'><span id='jdYJJ'><b id='jdYJJ'><form id='jdYJJ'><ins id='jdYJJ'></ins><ul id='jdYJJ'></ul><sub id='jdYJJ'></sub></form><legend id='jdYJJ'></legend><bdo id='jdYJJ'><pre id='jdYJJ'><center id='jdYJJ'></center></pre></bdo></b><th id='jdYJJ'></th></span></q></dt></tr></i><div id='jdYJJ'><tfoot id='jdYJJ'></tfoot><dl id='jdYJJ'><fieldset id='jdYJJ'></fieldset></dl></div>