Jquery select NEXT text field on Enter Key Press(Jquery 在 Enter 键上选择 NEXT 文本字段)
问题描述
我使用 jquery 创建了一个页面,加载时它会自动选择第一个文本字段.我希望它在按下 ENTER 键时移动到下一个字段.
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>
所以基本上:-
- 获取所有匹配 .vertical 的输入字段
- 查找当前文本框
- 寻找下一个
- 将焦点放在那个上
这篇关于Jquery 在 Enter 键上选择 NEXT 文本字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Jquery 在 Enter 键上选择 NEXT 文本字段


基础教程推荐
- 如何添加到目前为止的天数? 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- Bokeh Div文本对齐 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01