我想知道是否有可能得到最终结果keypress
事件?
目前,我正在使用keyup
因为它被激活了after用户已经在 texteara 中完成了文本编辑,但我编写了一个使用 Mootools 库执行类似操作的方法:
input.addEvent("keypress", function (input) {
var previous_result = this.value;
var end_result = this.value + input.key;
});
However, this method is horrible when dealing with special keys such as backspace, or if the user chooses to use CTRL + a && Backspace in which case the value of the input element would not be "an empty string".
我很好奇,因为我观察到 Google 的搜索引擎发送 XMLHttpRequest 并改变页面before the keyup
事件触发。
此外,他们使用的输入设法克服了我删除整个文本的问题,同时仍然享受奢侈keypress
.
这将使它工作:
input.addEvent( "keypress", function ( input ) {
setTimeout(function () {
input.value // returns the updated value
}, 0 );
});
现场演示: http://jsfiddle.net/yQQ5P/ http://jsfiddle.net/yQQ5P/(我使用内置API,因为我不知道Mootools)
因此,您使用零超时作为收益。这为浏览器的 UI 线程提供了更新输入值的机会。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)