我想通过jQuery更改复选框值,但Knockout绑定无法正常工作
var viewModel = {
myValue: ko.observable(true)
};
ko.applyBindings(viewModel);
$(':checkbox').prop({checked: false}).change();
答案 0 :(得分:1)
Knockout.js文档中描述了它:checked binding。
<p>Send me spam: <input type="checkbox" data-bind="checked: wantsSpam" /></p>
<script type="text/javascript">
var viewModel = {
wantsSpam: ko.observable(true) // Initially checked
};
// ... then later ...
viewModel.wantsSpam(false); // The checkbox becomes unchecked
</script>