【问题标题】:Check a disabled radio button with jquery使用 jquery 检查禁用的单选按钮
【发布时间】:2013-05-11 03:12:21
【问题描述】:

我正在使用 JQUery Mobile 1.3.1 检查禁用的单选按钮(即无法单击的单选按钮)。不幸的是,我的方法无法检查单选按钮禁用的单选按钮。我已经尝试在这里找到答案,但还没有找到任何有用的东西。这是我的代码:

<a href="#" id="activateRadio" data-role="button">Activate radio button flug!</a>
<input type="radio" name="radio1" id="radio-choice-1" value="choice-1" disabled />

以及 JQuery 移动功能:

$('#activateRadio').click(function(){         
      //check if radio button is  not checked

      if ( ! $("input[name='radio3']").is(':checked') ) {
        alert("The button was not checked. Now it should be checked!"); 
        //remove disabled attribute
        $("input[name='radio3']").removeAttr('disabled');
        $("input[name='radio3']").attr('checked', 'checked');
      }

      else {
        alert("The button is already checked!");
      }
});

另一个问题是如何在选中收音机时更改输入字段收音机的背景颜色。这在 CSS 中看起来如何?

【问题讨论】:

  • $("input[name='radio3']").prop('checked', true );

标签: javascript jquery mobile radio


【解决方案1】:

使用prop() 更改属性..attr 只是更改属性

  if ( ! $("input[name='radio3']").is(':checked') ) {
    alert("The button was not checked. Now it should be checked!"); 
    //remove disabled attribute
    $("input[name='radio3']").prop('disabled',false);
    $("input[name='radio3']").prop('checked', true);

    //or 
    $("input[name='radio3']").prop({'disabled':false',checked':true});

  }

  else {
    alert("The button is already checked!");
  }

不确定是radio3还是radio1,因为我在这里找不到radio3

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-29
    • 2011-04-16
    • 2011-08-05
    • 2012-02-02
    • 1970-01-01
    相关资源
    最近更新 更多