【发布时间】:2018-08-28 11:04:13
【问题描述】:
我添加了一个文本框,我想在每个应该调用的 keyup 函数上都这样做。
这是我的 html 代码:
<input type="text" id="description" class="form-control" maxlength="255" data-bind="event:{keyup: doSomething},value: property1,valueUpdate:'afterkeyup'"></input>
这是我的淘汰赛js代码:
define(['uiComponent','ko'], function(Component,ko) {
return Component.extend({
defaults:{
property1: ko.observable(),
tracks: {
property1: true
}
},
initialize: function () {
this._super();
},
getText: function () {
return "call the function here..";
},
doSomething : function(){
this.property1.subscribe(function(newValue){
console.log(newValue);
console.log("inside subscribe");
});
}
});
});
例如:当我按下 T 然后它会调用一次。之后,我按 E 然后它会调用两次而不是一次。
我想在每个 keyup 上都这样做,我想获取文本框值。
怎么做?
【问题讨论】:
标签: javascript events knockout.js event-handling dom-events