jQuery Mobile - 切换启用和禁用单选按钮的状态

时间:2012-01-31 09:47:20

标签: javascript jquery html css jquery-mobile

我有一个单选按钮,我希望能够通过jQuery Mobile启用和禁用。

单选按钮代码:

<input type="radio" disabled="disabled" value="option1" />

尝试:

$('input[type="radio"]').removeAttr('disabled');

$('input[type="radio"]').attr('disabled', '');

其中任何一个似乎都无法将按钮切换为启用。

3 个答案:

答案 0 :(得分:1)

<input type="radio" id="rdoToggle" value="option1" />
$("input[type='radio']").checkboxradio('enable');

Refer the documnentation,jQuery和jQuery Mobile在这个行动中有所不同。

$('#rdoToggle').toggle(function() {
  $("input[type='radio']").checkboxradio('enable');
}, function() {
  $("input[type='radio']").checkboxradio('disable');
});

答案 1 :(得分:0)

尝试使用$(elem).prop('propertyname')查看更多内容:http://api.jquery.com/prop/

答案 2 :(得分:0)

我认为复选框可能就是你要找的东西:

http://view.jquerymobile.com/master/demos/widgets/checkbox/

通过用户点击自动选中和取消选中复选框,而不像选择后仍然没有方便取消选择的单选按钮。