textarea 的 Keyup 事件
Keyup event for textarea
我正在使用虚拟键盘插件 http://mottie.github.io/Keyboard/。
在这里,我想在 mottie textarea 中触发一个按键事件,这样我就可以使用物理键盘在选定的语言中输入文本。
我试过这样的东西
$('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 of
event.which
. Instead you can use keypress
or keydown
or keyup
events separately to track the key code.
但是对于虚拟键盘你可以试试这样的Fiddle
希望对您有所帮助!
我正在使用虚拟键盘插件 http://mottie.github.io/Keyboard/。
在这里,我想在 mottie textarea 中触发一个按键事件,这样我就可以使用物理键盘在选定的语言中输入文本。
我试过这样的东西
$('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
希望对您有所帮助!