如何禁用个人复选框?

时间:2012-06-08 12:14:21

标签: php html xhtml

我想使用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。如何实现?

1 个答案:

答案 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
        }
    ?>