我正在使用虚拟键盘插件http://mottie.github.io/Keyboard/ 。
在这里,在 mottie 文本区域中,我想触发一个按键事件,以便我可以使用物理键盘输入所选语言中的文本。
我尝试过这样的事情
$('textarea[name=Notes]').keypress(function (e) {});
还有这样的
$("div.ui-keyboard-preview-wrapper").find('textarea[name=Notes]').keypress(function (e) {});
我也尝试过这样
$(".ui-keyboard-preview").keypress(function (e) {});
但是,它没有触发事件。有办法做到这一点吗?
最佳答案
尝试使用 input
事件,如下面的代码片段。它将跟踪 textarea
字段中的更改。对于老版本的IE,可以使用propertychange
事件来跟踪变化。
示例代码片段:
$(document).on('input propertychange', "textarea[name='Notes']", function () {
alert("Text Updated");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<textarea name="Notes" rows="4" cols="50">
Your text
</textarea>
注意:
The
input
event will trigger whenever the content of the text area getting changed. But it will not hold the key press information ofevent.which
. Instead you can usekeypress
orkeydown
orkeyup
events separately to track the key code.
但是对于虚拟键盘,你可以尝试这样的方法 Fiddle
希望这对您有帮助!
关于jquery - 文本区域的 Keyup 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31586244/