我的表单中有多个文本字段,我希望当用户在一个文本字段中输入数据时按Enter键,光标移动到当前文本字段旁边的另一个文本字段.我访问了一些问题,但没有发现它们有用.
$("#username").keypress(function (event) {
alert("inside function");
if(event.keyCode == 13) {
textboxes = $("input.username");
debugger;
currentBoxNumber = textboxes.index(this);
if (textboxes[currentBoxNumber + 1] != null) {
nextBox = textboxes[currentBoxNumber + 1];
nextBox.focus();
nextBox.select();
event.preventDefault();
return false;
}
}
});
Run Code Online (Sandbox Code Playgroud)
这是我的代码,我尝试了另一件事,当在最后一个文本字段中输入数据时,表单将提交鼠标单击按钮而不是输入按.