【问题标题】:jQuery radio button selection/deselectionjQuery单选按钮选择/取消选择
【发布时间】:2011-07-17 15:11:02
【问题描述】:

我目前在一些单选按钮上使用 jQuery。当用户单击一个收音机时,会调用一个函数,从所有其他收音机中删除checked 属性并禁用与其他收音机关联的输入字段。例如,当单击一个收音机时,

  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');   
  } 

由我的 Rails 助手调用, <%= radio_button_tag 'users', 'all', false, :id => 'radio1', :onclick => 'EnableRadio1()' %>
有什么更简洁和 jQueryesque 的方式来做到这一点?非常感谢。

【问题讨论】:

    标签: jquery ruby-on-rails


    【解决方案1】:

    如果我理解你...

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-02-21
      • 2011-10-26
      • 2018-07-15
      • 2016-05-25
      • 1970-01-01
      • 1970-01-01
      • 2015-07-01
      相关资源
      最近更新 更多