通知视图未显示已标记的复选框

时间:2016-09-08 06:27:26

标签: php

 <div class="control-group">
                                    <label class="control-label">Notification Views</label>
                                    <div class="controls">

                                        <label class="checkbox">
                                            <input type="checkbox" name="n_index[]" value="1" <? if (in_array("1", $arr))
                                                    {?>checked="checked"<?}?> class="a1" title="Choose"> Teachers
                                        </label>
                                        <label class="checkbox">
                                            <input type="checkbox" name="n_index[]" value="2" <? if (in_array("2", $arr))
                                                    {?>checked="checked"<?}?> class="a1" title="Choose"> Parents
                                        </label>
                                        <br>
                                        <label class="checkbox">
                                            <input type="checkbox" name="n_index[]" value="3" <? if (in_array("3", $arr))
                                                    {?>checked="checked"<?}?> class="a1" title="Choose"> Management
                                        </label>
                                        <label class="checkbox">
                                            <input type="checkbox" name="n_index[]" value="4" <? if (in_array("4", $arr))
                                                    {?>checked="checked"<?}?> class="a1" title="Choose"> Office
                                        </label>
                                        <?php echo form_error('n_index'); ?>
                                    </div>
                                </div>

这是我的代码,复选框未显示所选值。我如何在checkbox.please中获取所选项目帮助某人。

2 个答案:

答案 0 :(得分:1)

您在PHP语法中有错误。使用echo进行检查

<div class="control-group">
<label class="control-label">Notification Views</label>
<div class="controls">

    <label class="checkbox">
        <input type="checkbox" name="n_index[]" value="1" <?php if (in_array("1", $arr))
                {echo 'checked="checked"';}?> class="a1" title="Choose"> Teachers
    </label>
    <label class="checkbox">
        <input type="checkbox" name="n_index[]" value="2" <?php if (in_array("2", $arr))
                {echo 'checked="checked"';}?> class="a1" title="Choose"> Parents
    </label>
    <br>
    <label class="checkbox">
        <input type="checkbox" name="n_index[]" value="3" <?php if (in_array("3", $arr))
                {echo 'checked="checked"';}?> class="a1" title="Choose"> Management
    </label>
    <label class="checkbox">
        <input type="checkbox" name="n_index[]" value="4" <?php if (in_array("4", $arr))
                {echo 'checked="checked"';}?> class="a1" title="Choose"> Office
    </label>
<?php echo form_error('n_index'); ?>                                      
</div>
</div>

答案 1 :(得分:0)

您好php syntax错误只需尝试此

<label class="checkbox">
<input type="checkbox" name="n_index[]" value="1" <?php if(in_array(1,$arr)) echo 'checked="checked"'?> class="a1" title="Choose"> Teachers
</label>

执行此操作以休息3它将解决您的问题