第一种方法:
复制代码 代码如下:
$(document).ready(function () {
$(':input:text:first').focus();
$(':input:enabled').addClass('enterIndex');
// get only input tags with class data-entry
textboxes = $('.enterIndex');
// now we check to see which browser is being used
if ($.browser.mozilla) {
$(textboxes).bind('keypress', CheckForEnter);
} else {
$(textboxes).bind('keydown', CheckForEnter);
}
});
function CheckForEnter(event) {
if (event.keyCode == 13 && $(this).attr('type') != 'button' && $(this).attr('type') != 'submit' && $(this).attr('type') != 'textarea' && $(this).attr('type') != 'reset') {
var i = $('.enterIndex').index($(this));
var n = $('.enterIndex').length;
if (i < n - 1) {
if ($(this).attr('type') != 'radio')
{
NextDOM($('.enterIndex'),i);
}
else {
var last_radio = $('.enterIndex').index($('.enterIndex[type=radio][name=' + $(this).attr('name') + ']:last'));
NextDOM($('.enterIndex'),last_radio);
}
}
return false;
}
}
function NextDOM(myjQueryObjects,counter) {
if (myjQueryObjects.eq(counter+1)[0].disabled) {
NextDOM(myjQueryObjects, counter + 1);
}
else {
myjQueryObjects.eq(counter + 1).trigger('focus');
}
}

方法二(转载网络)
复制代码 代码如下:
document.onkeydown = function(evt) {
var isie = (document.all) ? true : false;
var key;
var srcobj;
alert(isie);
if (isie) {
key = event.keyCode;
srcobj = event.srcElement;
}
else {
alert(evt);
key = evt.which;
srcobj = evt.target;
}
if (key == 13 && srcobj.type != 'button' && srcobj.type != 'submit' && srcobj.type != 'reset' && srcobj.type != 'textarea' && srcobj.type != '') {
if (isie) {
event.keyCode = 9;
}
else {
var el = getNextElement(evt.target);
if (el.type != 'hidden')
el.focus();
else
while (el.type == 'hidden')
el = getNextElement(el);
el.focus();
return false;
}
}
}
document.onkeyup = function(evt) {
var isie = (document.all) ? true : false;
var key;
var srcobj;
alert(isie);
if (isie) {
key = event.keyCode;
srcobj = event.srcElement;
}
else {
alert(evt);
key = evt.which;
srcobj = evt.target;
}
if (key == 13 && srcobj.type != 'button' && srcobj.type != 'submit' && srcobj.type != 'reset' && srcobj.type != 'textarea' && srcobj.type != '') {
if (isie) {
event.keyCode = 9;
}
else {
var el = getNextElement(evt.target);
if (el.type != 'hidden')
el.focus();
else
while (el.type == 'hidden')
el = getNextElement(el);
el.focus();
return false;
}
}
}
function getNextElement(field) {
var form = field.form;
for (var e = 0; e < form.elements.length; e++) {
if (field == form.elements[e])
break;
}
return form.elements[++e % form.elements.length];
}

function document.onkeydown() {
var e = event.srcElement;
if (event.keyCode == 13 && e.tagName == "INPUT" && e.type == "text")
event.keyCode = 9;
}
标签:
回车,tab

免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com