2016-08-01 77 views
1

按钮点击不发射。感谢任何帮助。 这是jsfiddle链接。 https://jsfiddle.net/264aosnk/。 代码是这样的:淘汰赛 - 按钮点击不起作用

<body> 
    <div id="topNavConstant" > 
     <input placeholder="Enter search criteria" id="searchbox" data-  bind="value:criteria, valueUpdate:'afterkeydown'" type="search" autocomplete='off'/> 
     <input type="button" value="Click" data-bind="click:searchresults"/> 
    </div> 

//脚本

function myModel(){ 
var self = this; 
self.criteria = ko.observable(""); 

self.searchresults = ko.observable(function(){ 
    alert('Feature yet to come...'); 
}); 
} 
ko.applyBindings(new myModel()); 

我没有看到单击按钮时警报消息。

回答

0

绑定在knockout使用事件handler这意味着它将调用一个javascript函数而不是可观察的。 https://jsfiddle.net/kyr6w2x3/27/

更改您的点击功能这个

self.searchresults = function(){ 
    alert('Feature yet to come...'); 
}; 
+0

非常感谢你。 – MVS