简体   繁体   English

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

[英]jQuery Mobile – Toggle enable and disable state of a radio button

I have a radio button that I would like to be able to enable and disable through jQuery Mobile. 我有一个单选按钮,我希望能够通过jQuery Mobile启用和禁用。

Radio button code: 单选按钮代码:

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

tried: 尝试:

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

and

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

Neither of which seem to be able to toggle the button to enabled. 这两者似乎都无法将按钮切换为启用。

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

Refer the documnentation , jQuery and jQuery Mobile are different in this action. 请参阅文档 ,jQuery和jQuery Mobile在此操作中有所不同。

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

I think checkboxes might be what you're looking for instead: 我认为复选框可能是您正在寻找的东西:

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

Checkboxes are automatically selected and deselected through user clicks, unlike radio buttons that still don't seem to have a convenient way of being deselected after selection. 通过用户点击自动选择和取消选中复选框,这与单选按钮之后似乎没有方便取消选择的单选按钮不同。

尝试使用$(elem).prop('propertyname')了解更多信息: http ://api.jquery.com/prop/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM