【发布时间】:2014-10-23 23:18:37
【问题描述】:
我正在使用以下脚本:
if($('.fmscr:checked').val()){
$('.fmscr').closest('.form-group').removeClass('has-error');
$('.fmscr').closest('.form-group').addClass('has-success');
}else{
$('.fmscr').closest('.form-group').addClass('has-error');
$('.fmscr').closest('.form-group').removeClass('has-success');
}
在以下电台的表格中:
<div class='form-group'>
<div class='col-xs-12'>
<p>
Were you subject to the (FMSCR's) Department of Transportation (DOT) Regulations while employed?<span class='req'> *</span>
</p>
<label class='radio-inline'>
<input type='radio' class='fmscr checked' name='fmscr[]' value='1'> Yes
</label>
<label class='radio-inline'>
<input type='radio' class='fmscr checked' name='fmscr[]' value='-1'> No
</label>
</div>
</div>
单选按钮的数量不确定。上面的脚本在提交时运行,但它不计算单选按钮,直到两者都被选中,并且只有一个单选按钮被选中。那么我在这里做错了什么?无论数量如何,我都希望能够检查所有单选按钮,并让它们能够正确验证。如果需要任何进一步的信息,请告诉我!提前谢谢你。
【问题讨论】:
标签: javascript jquery html forms