我使用 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>
所以基本上:-
这篇关于Jquery 在 Enter 键上选择 NEXT 文本字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!