简体   繁体   中英

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.

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.

$('#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/

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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