检测文本输入字段中的Enter键 [英] Detect the Enter key in a text input field
本文介绍了检测文本输入字段中的Enter键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果在特定输入时按下输入,我正在尝试执行此功能。
I'm trying to do a function if enter is pressed while on specific input.
我做错了什么?
$(document).keyup(function (e) {
if ($(".input1").is(":focus") && (e.keyCode == 13)) {
// Do something
}
});
有没有更好的方法可以说,如果按下 .input1
做功能吗?
Is there a better way of doing this which would say, if enter pressed on .input1
do function?
推荐答案
$(".input1").on('keyup', function (e) {
if (e.keyCode == 13) {
// Do something
}
});
//keyup not compatible with Jquery select(), Keydown is.
这篇关于检测文本输入字段中的Enter键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文