我正在尝试使用 PHP 来执行此操作:
<if !empty($list) {echo
.
.
.
?>
并得到结果:
Additional options:
<p><input type="checkbox" name="1">1</input></label></p>
<p><input type="checkbox" name="2">2</input></label></p>
.
.
.
<p><input type="checkbox" name="n">n</input></label></p>
</legend>
</fieldset>
最佳答案
鉴于问题的上下文,我在这里猜测。但似乎您不了解复选框,因为您甚至没有为其分配一个值,并且在表单处理端循环遍历这将是一件痛苦的事情。
假设$list
是一个数组(借用Gazler的一些代码)
$cnt = count($list);
$checkBoxes = "";
for ($i=1; $i<$cnt; $i++) {
$checkBoxes .= '<p><input type="checkbox" name="checkBoxes" value="' . $i . '">' . $i . '</input></label></p>' . PHP_EOL;
}
echo $checkBoxes . '</legend>' . PHP_EOL . '</fieldset>';
然后在您的表单处理端,很容易像这样遍历选中的框:
if (isset($_POST['checkBoxes'])) {
foreach ($_POST['checkBoxes'] as $val) {
// $val will contain the value of the selected boxes
}
}
使用这个系统,它应该能带你到达你想去的地方。
关于php - 如何将 x-number HTML 格式的项目添加到我的页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3702883/