<input> 控件增加onkeypress事件
onkeypress="return handleEnter(this, event)"
JS如下:
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;
JQuery版:
$("input").keypress(function (e) { var keyCode = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode; if (keyCode == 13) { var i; for (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; });