我试图写这个:
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>');
}
});
});
但它不起作用。我究竟做错了什么?提前谢谢。
答案 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");
}
});
});
});
检查出来