我有一个单选按钮组的表格。我想将“选中”设置为默认的第二个单选按钮,如果用户单击第一个单选按钮,则在提交表单后保留该值。
请注意,我使用<span class="custom-radiobutton"></span>作为无线电按钮的样式,它的z-index比真正的有opacity:0的<input type="radio"要低。
这是我的代码片段:
<div class="group-wrapper">
<div class="radiobutton-wrapper boolean">
<span class="custom-radiobutton"></span>
<input type="radio" id="hosting-1" name="hosting[]" value="1" class="w100" <?php if ((isset($_POST['hosting'])) && ((isset($_POST['hosting'])) == 1)) {echo 'checked="checked"';}; ?> />
<label for="hosting-1">Sí</span>
</div>
<div class="radiobutton-wrapper boolean">
<span class="custom-radiobutton"></span>
<input type="radio" id="hosting-2" name="hosting[]" value="0" class="w100" <?php if ((!isset($_POST['hosting'])) || ((isset($_POST['hosting'])) == 0)) {echo 'checked="checked"';}; ?> />
<label for="hosting-2">No</label>
</div>
</div>附加信息:
我花了很多时间试图找出出了什么问题,所以任何帮助都是非常感谢的。干杯,
发布于 2015-12-17 11:35:59
<input type="radio" id="hosting-1" name="hosting[]" class="w100" checked="checked" /> 1在你的代码中试试这个。
例如:
<tr>
<td><br><b>Reservation Handling : <span style="color:#FF0000">* </span></td>
<td><br><input type="radio" name="reservation" value="Delighted" required> Delighted<br></input></td>
</tr>
<tr>
<td> </td>
<td><input type="radio" name="reservation" checked="checked" value="Satisfied"> Satisfied</input></td>
</tr>
<tr>
<td> </td>
<td><input type="radio" name="reservation" value="Dissatisfied"> Dissatisfied</input></td>
</tr>
<tr>
<td> </td>
<td><input type="radio" name="reservation" value="N/A"> N/A</input></td>
</tr> 发布于 2014-04-22 22:57:25
你的逻辑有错误。你用了两次isset。
<input type="radio" id="hosting-1" name="hosting[]" value="1" class="w100" <?php if ((isset($_POST['hosting'])) && ((isset($_POST['hosting'])) == 1)) {echo 'checked="checked"';}; ?> /> 您本质上是说isset等于1,在您的情况下,如果$_POST‘POST’有一个值,那么这个值总是正确的。
你应该这么做
<input type="radio" id="hosting-1" name="hosting[]" value="1" class="w100" <?php if (isset($_POST['hosting']) && $_POST['hosting'] == 1) {echo 'checked="checked"';} ?> /> https://stackoverflow.com/questions/23231168
复制相似问题