相关疑难解决方法(0)

将光标移动到下一个文本字段按Enter键

我的表单中有多个文本字段,我希望当用户在一个文本字段中输入数据时按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)

这是我的代码,我尝试了另一件事,当在最后一个文本字段中输入数据时,表单将提交鼠标单击按钮而不是输入按.

html javascript jquery

7
推荐指数
1
解决办法
3万
查看次数

标签 统计

html ×1

javascript ×1

jquery ×1