在keydown上获取.val()*不是* keyup [英] Get .val() on keydown *not* keyup
本文介绍了在keydown上获取.val()*不是* keyup的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在编写一个将小部件修改为文本区域的库,所以我需要检测用户何时开始输入内容:
I'm writing a library that amends a widget to a text area, so I need to detect when the user starts typing something:
this.$input.bind('keydown keyup', function() {
if (this.$input.val() == …) { … }
}
.val()
仅在<$ c $时更新c> keyup 被触发。这太延迟了。我想知道 keydown
上输入框的状态。你知道吗?一个改进 .val()
的库?
The .val()
only updates when keyup
is triggered. That's too much of a delay. I want to know the state of the input box on keydown
. Do you know of a library that improves .val()
?
推荐答案
找到一个看似完美的解决方案。使用上述HTML5 oninput
使用 onpropertychange
IE的后备。很棒。太棒了。其他快乐的话。
Found a seemingly perfect solution. Uses aforementioned HTML5 oninput
with onpropertychange
fallbacks for IE. Brilliant. Fantastic. Other happy words.
这篇关于在keydown上获取.val()*不是* keyup的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文