这是有效的:
视图.html
<div><input type="radio" name="radioPriority" data-bind="checked: priority" value="want" style="margin-top: -3px; margin-right: 3px;" />I want to</div>
<div><input type="radio" name="radioPriority" data-bind="checked: priority" value="need" style="margin-top: -3px; margin-right: 3px;"/>I need to</div>
控制器.js
function feedbackViewModel() {
var self = this;
self.priority = ko.observable("want");
//lots of other stuff
}
正如预期的那样,当您选择第二个收音机时,priority observable 的值将变为“需要”。但是,我想将 Twitter Bootstrap 按钮组用作收音机。这是我拥有的 HTML,但它并没有像预期的那样改变 observable:
<span class="btn-group" data-toggle="buttons-radio">
<button data-bind="checked: priority" type="button" class="btn" value="want">I want to</button>
<button data-bind="checked: priority" type="button" class="btn" value="need">I need to</button>
</span>
更新我在这里有一个 jsfiddle:http: //jsfiddle.net/a8wa8/6/ “priority1”是标准单选选择,“priority2”是引导按钮。