2 回答

TA贡献1820条经验 获得超9个赞
这是正确的代码之一。
<label>Subject : </label> <label><input type = "checkbox" name = "subject[]" id = "subject" <?php echo (in_array("Maths",$_POST["subject"]))?"checked" : " "?> value = "Maths"/>Maths</label> <label><input type = "checkbox" name = "subject[]" id = "subject" <?php echo (in_array("Maths",$_POST["subject"]))?"checked" : " "?> value = "English"/>English</label> <label><input type = "checkbox" name = "subject[]" id = "subject" <?php echo (in_array("Maths",$_POST["subject"]))?"checked" : " "?> value = "Tamil"/>Tamil</label>

TA贡献1784条经验 获得超8个赞
如果您想将所有复选框称为同名,则它们需要是一个数组
<label>
<input type="checkbox" name="subject[]" id="subject[]" <?php if (isset($_POST["subject"][0]) && $_POST["subject"][0]=="Maths") echo "checked";?> value = "Maths"/>Maths
</label>
<label>
<input type="checkbox" name="subject[]" id="subject[]" <?php if (isset($_POST["subject"][1]) && $_POST["subject"][1]=="English") echo "checked";?> value = "English"/>English
</label>
<label>
<input type="checkbox" name="subject[]" id="subject[]" <?php if (isset($_POST["subject"][2]) && $_POST["subject"][2]=="Tamil") echo "checked";?> value = "Tamil"/>Tamil
</label>
- 2 回答
- 0 关注
- 143 浏览
添加回答
举报