jQuery radio button selection/deselection
I'm currently using jQuery on some radio buttons. When the user clicks a radio, a function is called that removes the checked
attribute from all other radios and disables input fields associated with other radios. For example, when one radio is clicked,
function EnableRadio1() {
$('#x :input').attr('checked', false).attr('disabled', true);
$('#y :input').attr('checked', false).attr('disabled', true);
$('#z :input').attr('checked', false).attr('disabled', true);
$('#n :input').attr('checked', false).attr('disabled', true);
//enable segs_by_all options
$('#radio1 :input').removeAttr('disabled');
}
is called by my Rails helper,
<%= radio_button_tag 'users', 'all', false, :id => 'radio1', :onclick => 'EnableRadio1()' %>
If I understand you...
$(".radio").change(function(){
$(":radio").not(this).attr({"checked": false, "disabled": true});
$(this).removeAttr("disabled");
});
精彩评论