当选择来自2个不同组的特定无线电时,动态更改按钮链接

时间:2016-03-29 01:34:05

标签: jquery radio-button

我试图写这个:

when radio button 2 from Group 1 AND radio button 2 from Group 2 are selected
    replace Continue button with special link, dynamically while still on page
else
    keep/rewrite with this standard link, also on page

所以无论选择哪两个组合......

GROUP 1
Radio1 / Radio2

GROUP 2
Radio1 / Radio 2

如果选择了Radio 2 + Radio 2,则Continue按钮中的链接将自动更改,当选择任何其他组合时,它将立即更改回默认链接。

我有这个:

$(document).ready(function () {
    $('input[type="radio"]:checked').each(function() {
         if ($('#select_btn_forSelect2').is(':checked') && $('#select_btn_forSelectOther2').is(':checked')) {
             alert("Both are currently checked");
             $('.continue-button').replaceWith('<a class="btn btn-primary pull-right" href="/link1">' + "Continue" +'</a>');
         } else {
             alert("Only one, or neither of these was clicked");
             $('.continue-button').replaceWith('<a class="btn btn-primary pull-right" href="/link2">' + "Continue" +'</a>');
         }
    });
});

但它不起作用。我究竟做错了什么?提前谢谢。

1 个答案:

答案 0 :(得分:1)

OPTIONS
$(document).ready(function() {


  $('input[type="radio"]').each(function() {
    $(this).change(function() {// catch the check status on radio button change.
      if ($('#select_btn_forSelect2').is(':checked') && $('#select_btn_forSelectOther2').is(':checked')) {
        alert("Both are currently checked");
      } else {
        alert("Only one, or neither of these was clicked");
      }
    });
  });
});

检查出来