选择不同的单选按钮会转到不同的html页面

我有2套单选按钮,我想做以下事情:

1)当所有选择都为假时,显示validation消息。(这是有效的,但是当反复点击“保存”时,它会添加一个空白行,如何防止这种情况?)。

2)如果仅选择了Set 1或Set 2,则在Save上显示另一个的错误消息。

3)。 选择“设置1”时,“设置2”选项需要将用户带到不同的页面,具体取决于“是”或“否”。

提前致谢!!

链接到jsfiddle

 Please make a selection Radio Set 3 Yes     

Please make a selectionRadio Set 2 Yes   No

Save

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('
'); $('#val2').show().append('
'); } 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. } } });

在这里演示

试试这个:

 $('#Qbtn').click(function () { if ($('#attachYes').prop('checked') && $('#NotifYes').prop('checked')) { //go to http://www.yahoo.com window.location = "http://www.yahoo.com"; } else if ($('#attachYes').prop('checked') && $('#NotifNo').prop('checked')) { //go to http://www.cnn.com window.location = "http://www.cnn.com"; } else { //the validations are displaying correctly $('#val1, #val2').fadeOut('fast', function () { $(this).fadeIn('slow'); }); } }); 

如果我理解你的问题,这就是你需要的。 你真的想在每个错误上添加
吗? 我添加了淡入/淡出以避免这种情况。 希望它没问题。