我正在淘汰赛。我试图测试输入键按下或模糊事件。
HTML:
<input class="percent-text" data-bind="numeric: Percent, value: Percent, event: { keypress: $root.percentUpdate, blur: $root.percentUpdate }" type="number" min="1" max="100" oninput="maxlength(this)" maxlength="3" />
淘汰模型:
self.percentUpdate = function (data, event) {
if (event.keyCode === 13 || TEST FOR BLUR HERE) {
....
不确定如何测试模糊事件。救命 感谢
答案 0 :(得分:2)
为什么不只是额外的功能:
<input class="percent-text" data-bind="numeric: Percent, value: Percent, event: { keypress: $root.keypress, blur: $root.blur }" type="number" min="1" max="100" oninput="maxlength(this)" maxlength="3" />
和
self.keypress = function(data, event){
self.percentUpdate(data, 'keypress', event.keyCode);
};
self.blur = function(data){
self.percentUpdate(data, 'blur');
}
self.percentUpdate = function (data, event, keyCode) {
if (event === 'blur' && keyCode === 13) {
...}
答案 1 :(得分:2)
不熟悉淘汰赛,但我认为常规的JavaScript会起作用:
self.percentUpdate = function (data, event) {
if (event.keyCode === 13 || event.type==='blur') {