我正在使用iCheck-bootstrap v1.07的纯css插件及knockout v3.4.2。在没有淘汰赛的情况下使用iCheck时,复选框可以完美呈现。但是,当我添加knockout和bootstrap时,这两个似乎不能一起工作。我在下面粘贴了一段代码。请帮忙解决我需要纠正的问题?
function model() {
var self = this;
selectOne = ko.observable(true);
selectTwo = ko.observable(false);
}
var mymodel = new model();
$(document).ready(function() {
ko.applyBindings(mymodel);
});
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://raw.githubusercontent.com/bantikyan/icheck-bootstrap/master/icheck-bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.4.2/knockout-min.js"></script>
<div class="checkbox icheck-default">
<input type="checkbox" data-bind="checked: selectOne" />
<label>Select One with iCheck</label>
</div>
<div class="checkbox icheck-default">
<input type="checkbox" data-bind="checked: selectTwo" />
<label>Select One with iCheck</label>
</div>
<hr />
<div>
<input type="checkbox" data-bind="checked: selectOne" />
<label>Select One w/o iCheck</label>
</div>
<div>
<input type="checkbox" data-bind="checked: selectTwo" />
<label>Select Two w/o iCheck</label>
</div>
答案 0 :(得分:0)
似乎工作正常,也许你的cdn for icheck并没有正常工作。我正在使用https://cdn.rawgit.com/bantikyan/icheck-bootstrap/master/icheck-bootstrap.min.css
function model() {
var self = this;
selectOne = ko.observable(true);
selectTwo = ko.observable(false);
}
var mymodel = new model();
$(document).ready(function() {
ko.applyBindings(mymodel);
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://cdn.rawgit.com/bantikyan/icheck-bootstrap/master/icheck-bootstrap.min.css" rel="stylesheet" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.4.2/knockout-min.js"></script>
<div class="checkbox icheck-default">
<input type="checkbox" data-bind="checked: selectOne" />
<label>Select One with iCheck</label>
</div>
<div class="checkbox icheck-default">
<input type="checkbox" data-bind="checked: selectTwo" />
<label>Select One with iCheck</label>
</div>
<hr />
<div>
<input type="checkbox" data-bind="checked: selectOne" />
<label>Select One w/o iCheck</label>
</div>
<div>
<input type="checkbox" data-bind="checked: selectTwo" />
<label>Select Two w/o iCheck</label>
</div>
&#13;