我有 2 组单选按钮,我想执行以下操作:
1)当所有选择都为假时,显示验证消息。(这是有效的,但是当反复单击“保存”时会添加一个空白行,我该如何防止这种情况发生?)。
2) 如果只选择了 Set 1 或 Set 2,则在保存时显示另一个错误消息。
3)。选择 Set 1 时,Set 2 选择需要根据 Yes 或 No 将用户带到不同的页面。
提前致谢!!
<span id="val1" style="display:none; color:red;"> Please make a selection</span>
<strong>Radio Set 3</strong>
<input type="radio" name="radio" id="attachYes" />Yes
<input type="radio" name="radio" id="attachNo" />
<label for="radio2">No</label>
<p>
<span id="val2" style="display:none; color:red;"> Please make a selection</span><strong>Radio Set 2</strong>
<input type="radio" name="radio2" id="NotifYes" />Yes
<input type="radio" name="radio2" id="NotifNo" />No
</p>
<p>
<a href="#" id="Qbtn">Save</a>
</p>
JS
$('#Qbtn').click(function () {
if ((!$('#attachYes').attr('checked') === true) && (!$('#attachNo').attr('checked') === true) && (!$('#NotifYes').attr('checked') === true) && (!$('#NotifNo').attr('checked')) === true) {
//the validations are displaying correctly
$('#val1').show().append('<br>');
$('#val2').show().append('<br>');
} else {
if (($('#attachYes').attr('checked') === true) || ($('#attachNo').attr('checked') === true) && (!$('#NotifNo').attr('checked') === true) && ($('#NotifYes').attr('checked')) === true) {
//the user should be taken to page1.html when clicking save and it isn't doing it
window.location = "page1.html";
//then how do I write if either of radio set 1 is true and #NotifNo of Radio set 2 is true go to page2.html.
}
}
});