我想知道如何正确地选中复选框。
当前在循环内循环......
首先,foreach它列出了所有要标记的选项,如下图所示:
在此处输入图片说明
第二个foreach是标记来自数据库的选项。它使用此代码进行检查<?php if($checkIni[$key] == "tem"){echo "checked ";}; ?>。变化的是TEM, NAO, AVA 的值。
<?php
$checklistIni = "a:16:{i:0;s:3:"nao";i:1;s:3:"ava";i:2;s:3:"tem";i:3;s:3:"tem";i:4;s:3:"tem";i:5;s:3:"tem";i:6;s:3:"tem";i:7;s:3:"tem";i:8;s:3:"tem";i:9;s:3:"tem";i:10;s:3:"tem";i:11;s:3:"tem";i:12;s:3:"tem";i:13;s:3:"tem";i:14;s:3:"tem";i:15;s:3:"tem";}";
$checkIni = unserialize($checklistIni );
foreach($rsChecklist as $checklist) {
foreach($checkIni as $key => $val){
?>
<tr>
<td class="texto-branco">
<?php echo $checklist['nome'] ?>
</td>
<td><label><input value="tem" name="checklistFim<?php echo $checklist['ID_Checklist'] ?>" class="checklistFim" type="radio" <?php if($checkIni[$key] == "tem"){echo "checked ";}; ?> /><span></span></label></td>
<td><label><input value="nao" name="checklistFim<?php echo $checklist['ID_Checklist'] ?>" class="checklistFim" type="radio" <?php if($checkIni[$key] == "nao"){echo "checked ";}; ?> /><span></span></label></td>
<td><label><input value="ava" name="checklistFim<?php echo $checklist['ID_Checklist'] ?>" class="checklistFim" type="radio" <?php if($checkIni[$key] == "ava"){echo "checked ";}; ?> /><span></span></label></td>
</tr>
<?php
};
};
?>
ITMISS