Jquery在Enter Key Press上选择NEXT文本字段 [英] Jquery select NEXT text field on Enter Key Press
本文介绍了Jquery在Enter Key Press上选择NEXT文本字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用jquery创建了一个页面,并在加载时自动选择第一个文本字段。当按下ENTER键时,我希望它移动到下一个区域。
$('。barcodeField input')。 bind('keyup',function(event){
if(event.keyCode == 13){
$(this + input)。focus();
}
});
我找不到任何可以在网络上运行的东西。我已经在论坛上搜索过。
解决方案
我已经创建了一个可以完成您所需功能的小功能。这是我使用的版本,因此您可能需要更改类名称,但您应该明白。
<脚本类型= 文本/ JavaScript的 >
$(document).ready(function(){
$(。vertical)。keypress(function(event){
if(event.keyCode == 13){
textboxes = $(input.vertical);
debugger;
currentBoxNumber = textboxes.index(this);
if(textboxes [currentBoxNumber + 1]!= null){
nextBox = textboxes [currentBoxNumber + 1]
nextBox.focus();
nextBox.select();
event.preventDefault();
返回false
}
}
});
})
< / script>
所以基本上: -
- 获取与.vertical匹配的所有输入字段
- 查找哪个是当前文本框
- 查找下一个
- 将焦点设置在那个
上
I have made a page using jquery, and on load it selects the first text field automatically. I want it to then move to the next field when the ENTER key is pressed.
$('.barcodeField input').bind('keyup', function(event) {
if(event.keyCode==13){
$("this + input").focus();
}
});
I can't find anything that works on the net. And I've scoured the forums.
解决方案
I've created a little function which can do what you need. This is the version I use so you may need to change the class names but you should get the idea.
<script type="text/javascript">
$(document).ready(function(){
$(".vertical").keypress(function(event) {
if(event.keyCode == 13) {
textboxes = $("input.vertical");
debugger;
currentBoxNumber = textboxes.index(this);
if (textboxes[currentBoxNumber + 1] != null) {
nextBox = textboxes[currentBoxNumber + 1]
nextBox.focus();
nextBox.select();
event.preventDefault();
return false
}
}
});
})
</script>
So basically:-
- Get all the input fields matching .vertical
- Find which is the current text box
- Find the next one
- Set the focus on that one
这篇关于Jquery在Enter Key Press上选择NEXT文本字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文