按Enter键时如何进入下一个文本框? [英] How to go to next textbox when enter is pressed?
本文介绍了按Enter键时如何进入下一个文本框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好我正在学习Javascript,我想问你们,当我按下键盘上的输入按钮后,如何在输入文字后进入下一个文本框。谢谢
Hi guys I'm learning Javascript and I would like to ask you guys how can I go to the next textbox after inputing text when I press the enter button in the keyboard. thank you
推荐答案
您可以使用 .keyup()
来跟踪当用户在一个字符中完成键并且 e.keyCode
以获得按下哪个键时,如果它是 13
(表示输入)然后使用 .focus()
来聚焦下一个文本框元素:
You can use .keyup()
to keep track of when user finish key in a character and e.keyCode
to get which key was pressed, if it's 13
(means enter) then use .focus()
to focus the next textbox element:
$('input[type="textbox"]').keyup(function(e) {
if(e.keyCode == 13) {
$(this).next().focus();
}
});
Fiddle Demo
这篇关于按Enter键时如何进入下一个文本框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文