<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>
这是我的代码,复选框没有显示所选值。我如何在复选框中获得选中的项目。
PHP语法错误。使用echo使checked
<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>
你有一个PHP语法错误,简单地试试:
<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>