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

javascript - use Jquery to check checkbox in Jquery buttonset - Stack Overflow

programmeradmin2浏览0评论

I have some checkboxes in a button set and I want to use Jquery to check one of the checkboxes.

It works, however, the visual representation of the checkbox does not update. ie, after executing $('#chk').attr('checked',true); the checked value is true, but the checkbox apears unchecked.

Demoed here: /

Thanks!

I have some checkboxes in a button set and I want to use Jquery to check one of the checkboxes.

It works, however, the visual representation of the checkbox does not update. ie, after executing $('#chk').attr('checked',true); the checked value is true, but the checkbox apears unchecked.

Demoed here: http://jsfiddle/kralco626/jzVjT/1/

Thanks!

Share Improve this question edited Dec 6, 2010 at 14:20 kralco626 asked Dec 6, 2010 at 14:14 kralco626kralco626 8,64441 gold badges115 silver badges171 bronze badges 3
  • 1 Note: when you click the button in the jsfiddle example, the checkbox is being checked. You can tell because when you click the checkbox after clicking the button the checkbox still appears in the "unchecked" state. – kralco626 Commented Dec 6, 2010 at 14:16
  • Nick Craver's answer should work. As an aside, I'd say if what you really want is a buttonset, then you probably want to have your original source be a group of radio buttons, not checkboxes. Usually a buttonset provides a group of mutually exclusive options, whereas checkboxes each toggle an individual property on or off (those turn into toggle buttons when you call .button() on them directly). – RwwL Commented Dec 6, 2010 at 14:20
  • I want checkbox functionality, not radio button functionality. A Jquery buttonset will either be a checkbox type set or a radio button type set based on whether it contains inputs of type checkbox, or radio. – kralco626 Commented Dec 6, 2010 at 14:20
Add a ment  | 

2 Answers 2

Reset to default 16

You need to call the refresh method on the buttonset to update the visual state after programmatic changes to the checked state, like this:

$("#test").buttonset("refresh");

You can test it out here.

Try

'true'

rather than

true

Attributes are always string values.

Edit:

Never mind. No clue on buttonset functionality but things aren't behaving normally. Check the documentation for the API.

发布评论

评论列表(0)

  1. 暂无评论