ı有10组收音机。每组有2个或3个或更多的无线电,这并不重要。您需要从每个组中至少选择一个无线电。
当您提交表单时,如果其中任何一个(组)留空,则必须检查并返回错误。
ı尝试了一些代码,但无法解决它。ı编写此代码是为了查找和显示错误,但它会一个接一个地查找,所以如果有1个完整的错误,它就会提交表单。
$('#myForm').submit(function () {
$(".radiogrup").each(function () {
var sel = $(this).find("input[type='radio']:checked").val();
if (sel == null) {
alert("error msg");
return false;
}
});
});html:
如果你知道如何配置required="required“,也许ı可以使用它。
<div class="radiogrup">
<form id="form1" name="form1" method="post" action="">
<p>
<label>
<input type="radio" name="RadioGroup1" value="radyo" id="RadioGroup1_0" />
Radyo</label>
<br />
<label>
<input type="radio" name="RadioGroup1" value="radyo" id="RadioGroup1_1" />
Radyo</label>
<br />
<input name="" type="submit" />
</p>
</form>
</div>发布于 2012-08-30 14:48:18
function ValidateRadioButtons() { //Function for Validating If Radio Button isselected
var ischecked = false;
$('.radiogrup').children('radio').each(function () { //LoopingthroughradioButtons
// "this" is the current element(radio) in the loop
if ($(this).is(':checked')) {
ischecked = true; //Radio Button is Checked
}
});
if (ischecked == true) {
alert("Validation Passed");
}
else {
alert("Please select a Radio Button");
}
}https://stackoverflow.com/questions/12191078
复制相似问题