JS 回车跳转

 

window.onload = function () {
SeteasyuiTheme();
jQuery(':input:enabled').addClass('enterIndex');
var textboxes = jQuery('.enterIndex');
if ($.support.mozilla) {
jQuery(textboxes).bind('keypress', CheckForEnter);
} else {
jQuery(textboxes).bind('keydown', CheckForEnter);
}
};

 

function CheckForEnter(event) {

if (event.keyCode == 13 && $(this).attr('type') != 'submit' && $(this).attr('type') != 'reset' && $(this).attr('type') != 'hidden') {
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 if (myjQueryObjects.eq(counter + 1).attr('type') == 'hidden') {
NextDOM(myjQueryObjects, counter + 1);
}
else if (myjQueryObjects.eq(counter + 1).attr('readonly') == 'readonly') {
NextDOM(myjQueryObjects, counter + 1);
}
else {

if (myjQueryObjects.eq(counter + 1).attr('type') == 'button') {

myjQueryObjects.eq(counter + 1).trigger('click');
} else {

myjQueryObjects.eq(counter + 1).focus();
myjQueryObjects.eq(counter + 1).trigger('focus');
myjQueryObjects.eq(counter + 1).trigger('select');
}
}
}

posted @ 2014-04-17 09:55  放哨De老鼠  阅读(460)  评论(0编辑  收藏  举报