这是您的JSFiddle的更新
<input data-bind="value: demo, valueUpdate: 'afterkeydown'" />
var viewModel = function () {
var self = this;
self.demo = ko.observable('');
self.myFunction = function(){
alert("fired");
}
}
var VM = new viewModel();
ko.applyBindings(VM);
VM.demo.subscribe(function(){
VM.myFunction();
});
我希望这是你想要的??
谢谢
编辑:
没有订户。没有订阅者的 JSFiddle
var viewModel = function () {
var self = this;
self.demo = ko.observable('');
self.myFunction = function () {
alert("fired");
}
self.worker = ko.computed(function () {
if (self.demo()) self.myFunction();
}, this);
}
var VM = new viewModel();
ko.applyBindings(VM);