开发者

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()' %>

What's a more succinct and jQueryesque w开发者_运维知识库ay to do this? Many thanks.


If I understand you...

$(".radio").change(function(){
    $(":radio").not(this).attr({"checked": false, "disabled": true});
    $(this).removeAttr("disabled");
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜