【发布时间】:2016-02-12 08:50:15
【问题描述】:
我正在构建一个表单页面,但当我想实现一个“输入键”功能来同时触发验证和方法时,我遇到了困难。
Here's a JS-Fiddle of the example
如您所知,您需要按两次 Enter 才能触发该方法。我相信 knockout.validation 有它自己的事件绑定,也许这就是为什么
<input type="text" data-bind="event: {'keypress': enterKey}, value: customer.telephone">
<input type="button" data-bind="click: sendCustomer" value="send">
enterKey = function (d, e) {
if (e.keyCode == 13) {
alert("enter has been pressed..");
sendCustomer();
}
return true;
}
【问题讨论】:
-
请在问题本身中包含完整但最少的repro。这样,如果链接失效或 jsfiddle 失效,您的问题仍然对未来遇到同样问题的访问者有用。
标签: javascript knockout.js knockout-validation