這是我的代碼。knockoutJS,觸發事件,但event.which仍未定義
<input type="text" placeholder="Add New Tag" data-bind="value: tagToAdd, valueUpdate: 'afterkeydown', event: { keypress: addOnEnter }" />
這是我的淘汰賽碼。
self.addOnEnter = function (event) {
console.log(event.which);
var keyCode = (event.which ? event.which : event.keyCode);
if (keyCode === 13) {
self.addTag();
}
return true;
};
當我在輸入字段中輸入某些內容時,我記錄了事件,不斷得到未定義的事件。我不知道爲什麼我無法捕捉哪個事件被解僱。
你可以在jsFiddle上測試我的代碼。 http://jsfiddle.net/GBLNR/6/
只需在輸入字段中輸入任何內容,然後從控制檯觀看結果。
非常感謝你,沒辦法,我可以搞清楚自己。 – qinking126