gpt4 book ai didi

javascript - Bootstrap 单选按钮组 knockout 绑定(bind)不起作用

转载 作者:行者123 更新时间:2023-11-30 07:08:18 24 4
gpt4 key购买 nike

我遵循了这个: http://volaresystems.com/blog/post/2013/12/09/Using-Bootstrap-3-radio-button-groups-with-Knockout-3-data-bindings(jQuery 2.0.3, Bootstrap 3.0.3, Knockout 3.0.0)

据我所知,唯一的区别是 jQuery、Knockout 和 Bootstrap 版本号,但主要版本号是匹配的。 http://jsfiddle.net/csabatoth/rLtL16xk/12/(jQuery 2.1.3, Bootstrap 3.3.4, Knockout 3.3.0)

<p>
Currently selected: <span data-bind="text: selectedOption"></span>
</p>

<div class="btn-group-vertical" data-toggle="buttons">
<label class="btn btn-lg btn-primary" data-bind="css: { 'active': selectedOption() === 'Purchase Target Cat' }">
<input type="radio" name="options" id="option1" data-bind="checked: selectedOption, checkedValue: 'Purchase Target Cat'">Purchase Target Cat
</label>
<label class="btn btn-lg btn-primary" data-bind="css: { 'active': selectedOption() === 'Purchase Existing Cat' }">
<input type="radio" name="options" id="option2" data-bind="checked: selectedOption, checkedValue: 'Purchase Existing Cat'">Purchase Existing Cat
</label>
<label class="btn btn-lg btn-primary" data-bind="css: { 'active': selectedOption() === 'Existing Dog Purchases Target Cat' }">
<input type="radio" name="options" id="option3" data-bind="checked: selectedOption, checkedValue: 'Existing Company Purchases Target Company'">Existing Dog Purchases Target Cat
</label>
</div>

var viewModel = function () {
var self = this;
self.selectedOption = ko.observable("Target Cat");
}

$(document).ready(function () {
var vm = new viewModel();
ko.applyBindings(vm);
});

谁能指出为什么这不起作用?绑定(bind)只是一种方式。它获得初始值,但不再有用。

最佳答案

尝试 <div class="btn-group-vertical" data-toggle="buttons">删除 data-toggle="buttons"

添加CSS:

label.btn > input[type='radio']
{
display: none;
}

js:删除$(document).ready(function () {

DEMO

关于javascript - Bootstrap 单选按钮组 knockout 绑定(bind)不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30317032/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com