Javascript 选中数据绑定调用函数时的knockoutjs
我需要做以下事情:当用户选中复选框时,调用一些函数Javascript 选中数据绑定调用函数时的knockoutjs,javascript,data-binding,knockout.js,Javascript,Data Binding,Knockout.js,我需要做以下事情:当用户选中复选框时,调用一些函数 <input type="checkbox" data-bind="what to write here?" /> 我还没有找到任何关于这方面的文档。您需要的是 演示 或者,如果您想使用选中的绑定,您可以订阅属性的更改事件: <input type="checkbox" data-bind="checked: isChecked" /> 演示是否可以区分何时选中复选框和何时取消选中复选框?使用订阅时,您可以通过以下方
<input type="checkbox" data-bind="what to write here?" />
我还没有找到任何关于这方面的文档。您需要的是
演示
或者,如果您想使用选中的
绑定,您可以订阅属性的更改事件:
<input type="checkbox" data-bind="checked: isChecked" />
演示是否可以区分何时选中复选框和何时取消选中复选框?使用
订阅
时,您可以通过以下方式获得值:this.isChecked.subscribe(函数(newValue){
请参阅,在单击绑定的情况下,您可以通过this.someFunction=函数(数据、事件){console.log获得(event.target.checked);
请参见:
<input type="checkbox" data-bind="click: someFunction" />
var ViewModel = function(data, event) {
this.someFunction = function() {
console.log(event.target.checked); // log out the current state
console.log("1");
return true; // to trigger the browser default behavior
}
};
<input type="checkbox" data-bind="checked: isChecked" />
var ViewModel = function() {
this.isChecked = ko.observable();
this.isChecked.subscribe(function(newValue){
this.someFunction(newValue);
}, this);
this.someFunction = function(value) {
console.log(value); // log out the current state
console.log("1");
}
};