【发布时间】:2014-06-07 12:16:05
【问题描述】:
我有一个带有单选按钮组的表单。我想将第二个单选按钮设置为默认值,如果用户单击第一个单选按钮,则在提交表单后也保留该值。
请注意,我使用<span class="custom-radiobutton"></span> 来设置单选按钮的样式,z-index 低于真正的<input type="radio",后者具有opacity:0。
这是我的代码的 sn-p:
<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>
其他信息:
- 我正在使用 HTML5。
- 我正在使用 PHP 验证表单(我想保留这个,即使我知道 jQuery+PHP 验证可能更好)。
- 我注意到我需要单击两次才能选择第一个单选按钮。这只发生在原始状态。在此之后,它可以一键运行,正如预期的那样。
我花费了大量时间试图找出问题所在,因此我们将非常感谢您提供任何帮助。 干杯,
【问题讨论】:
-
你不需要为单选按钮做checked="checked",你可以使用checked。前任。
标签: php forms validation radio-button