js中Enter切换文本框,方便快捷输入

<input name="test"  type="text" onkeypress="return handleEnter(this, event)">

 

 function handleEnter (field, event) {
        var keyCode = event.keyCode ? event.keyCode : event.which ?
            event.which : event.charCode;
        if (keyCode == 13) {
            var i;
            for (i = 0; i < field.form.elements.length; i++)
                if (field == field.form.elements[i])
                    break;
            i = (i + 1) % field.form.elements.length;
            field.form.elements[i].focus();
            return false;
        }
        else
            return true;
    }

 

posted @ 2021-05-24 11:05  ZXJ~佳  阅读(226)  评论(0编辑  收藏  举报