2 回答

TA貢獻2016條經驗 獲得超9個贊
例子:
<?php
$options = [
["artistid" => 1, "req_id" => 1, "requirement" => "Microphone"],
["artistid" => 1, "req_id" => 2, "requirement" => "Table"],
["artistid" => 1, "req_id" => 3, "requirement" => "Chair"],
["artistid" => 1, "req_id" => 4, "requirement" => "Microphone Stand "],
["artistid" => 1, "req_id" => 5, "requirement" => "Personal Artifacts"],
["artistid" => 1, "req_id" => 6, "requirement" => "Set Dressing"],
["artistid" => 1, "req_id" => 7, "requirement" => "Raised Step "]
];
$checkedOptions = [2, 7];
foreach ($options as $option) {
?>
<label class='checkbox'>
<input type="checkbox" name="requirement[]" value="<?= $option['req_id']?>" <?= in_array($option['req_id'], $checkedOptions) ? 'checked' : '' ?> >
<?= $option['requirement'] ?>
</label>
<br>
<?php
}
?>

TA貢獻1826條經驗 獲得超6個贊
您需要一個條件語句來查看變量是否設置為來自$_POST[]或$row[]數組的輸入字段的名稱,以及是否設置回顯checked輸入字段中的屬性。如果您動態(tài)創(chuàng)建輸入列表,則需要對 value 屬性執(zhí)行相同的操作。
<input type='checkbox' name='microphone' value='$eqid' <?php if($eqname === "microphone"){ echo 'checked'; }>
<input type='checkbox' name='table' value='$eqid' <?php if($eqname === "table"){ echo 'checked'; }>
<input type='checkbox' name='chair' value='$eqid' <?php if($eqname === "chair"){ echo 'checked'; }>
<input type='checkbox' name='microphone_stand' value='$eqid' <?php if($eqname === "microphone_stand"){ echo 'checked'; }>
<input type='checkbox' name='personal_artifacts' value='$eqid' <?php if($eqname === "personal_artifacts"){ echo 'checked'; }>
<input type='checkbox' name='set_dressing' value='$eqid' <?php if($eqname === "set_dressing"){ echo 'checked'; }>
<input type='checkbox' name='raised_step' value='$eqid' <?php if($eqname === "raised_step"){ echo 'checked'; }>
<input type='checkbox' name='other' value='$eqid' <?php if($eqname === "other"){ echo 'checked'; }>
- 2 回答
- 0 關注
- 155 瀏覽
添加回答
舉報