我想使用for checkbox
在html table
中显示数组值,然后显示loop
:
<?php
for ($j = 0; $j < $data['user']['droit']['cnt']; $j++)
{
?>
<table>
<tr>
<td><?php echo $data['user']['droit'][$j]['menu_titre']; ?></td>
<?php
$checked = "";
if (is_array($data['user_droit']) && count($data['user_droit']) > 0 && in_array($data['user']['droit'][$j]['menu_code'], $data['user_droit']))
$checked = " checked ";
?>
<td><input type="checkbox" name="<?php echo $data['user']['droit'][$j]['menu_code']; ?>"
value="<?php echo $data['user']['droit'][$j]['menu_code']; ?>" <?php echo $checked ?> />
</td>
</tr>
</table>
<?php
}
?>
如果从循环中检查单个复选框,我不知道如何使其成为disabled
。如何实现?
答案 0 :(得分:1)
或设置$checked = " checked disabled ";
<?php
for ($j = 0; $j < $data['user']['droit']['cnt']; $j++)
{
?>
<table>
<tr>
<td><?php echo $data['user']['droit'][$j]['menu_titre']; ?></td>
<?php
$checked = "";
if (is_array($data['user_droit']) && count($data['user_droit']) > 0 && in_array($data['user']['droit'][$j]['menu_code'], $data['user_droit']))
{
$checked = " checked disabled ";
}
?>
<td><input type="checkbox" name="<?php echo $data['user']['droit'][$j]['menu_code']; ?>"
value="<?php echo $data['user']['droit'][$j]['menu_code']; ?>" <?php echo $checked ?> />
</td>
</tr>
</table>
<?php
}
?>