最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jQuery manually set buttonset radios - Stack Overflow

programmeradmin3浏览0评论

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 all.

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

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 all.

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

Share Improve this question edited Feb 28, 2011 at 18:22 Yottagray asked Feb 28, 2011 at 18:03 YottagrayYottagray 2,5925 gold badges32 silver badges45 bronze badges 8
  • First off: the checked property is a Boolean value, it's set by being either present or not-present. It doesn't require an attribute. Try using: attr('checked',true) instead. It might make a difference. – David Thomas Commented Feb 28, 2011 at 18:05
  • This is not a problem, it works fine either way when jQuery UI is not used. – Yottagray Commented Feb 28, 2011 at 18:20
  • 1 You might want to consider posting a JS Fiddle demo that reproduces your problem; that way we can see what's interacting with what. – David Thomas Commented Feb 28, 2011 at 18:26
  • 1 @Yottagray - I can't get "buttonset()" to do anything at all in a jsfiddle - what is it supposed to do? The documentation for "buttonset" is deficient, to say the least ... – Pointy Commented Feb 28, 2011 at 18:26
  • 1 Here's a jsFiddle where setting the radio button "checked" attribute works perfectly well: jsfiddle.net/Pointy/Nggxc/3 – Pointy Commented Feb 28, 2011 at 18:41
 |  Show 3 more comments

1 Answer 1

Reset to default 23

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)

  1. 暂无评论