开发者

jQuery manually set buttonset radios

开发者 https://www.devze.com 2023-02-14 03:27 出处:网络
I am trying to manually set a radio button to checked, but there is a problem. The code works just fine:

I am trying to manually set a radio button to checked, but there is a problem. The code works just fine:

$('#'+align+'Text').attr("checked","checked");

But when I put jQuery UI into practice and make the radios a buttonset, everything breaks. Again, everything works fine until I put in the .buttonset(), then they look much better than normal radios, but the setting above does not work at 开发者_StackOverflow社区all.

EMPHASIS ON THE FOLLOWING:

Has anyone been able to manually set a radio button while .buttonset() is active on those radios?


All you need to do is call the "refresh" operation on the button widget after setting the "checked" attribute.

$('#'+align+'Text').attr("checked","checked").button('refresh');

Here's the jsfiddle.

Note that setting the "checked" property can (and, some would say, should) be set with the .prop() function:

$('#' + align + 'Text').prop('checked', true).button('refresh');
0

精彩评论

暂无评论...
验证码 换一张
取 消