jQuery阻止回车form表单提交

$(function(){
$("input").keypress(function (e){
        var keyCode = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;  
            if (keyCode == 13){
                for (var i = 0; i < this.form.elements.length; i++) {  
                if (this == this.form.elements[i]) break;  
            }  
            i = (i + 1) % this.form.elements.length;  
            this.form.elements[i].focus();  
            return false;  
        }else{
            return true ; 
        }
    });
});

你可能感兴趣的:(jQuery阻止回车form表单提交)