DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> 關於JavaScript >> JS實現Enter鍵跳轉及控件獲得焦點
JS實現Enter鍵跳轉及控件獲得焦點
編輯:關於JavaScript     
復制代碼 代碼如下:
//回車跳轉
jQuery(document).ready(function () {
//$(':input:text:first').focus();
jQuery(':input:enabled').addClass('enterIndex');
// get only input tags with class data-entry
textboxes = jQuery('.enterIndex');
// now we check to see which browser is being used
if (jQuery.browser.mozilla) {
jQuery(textboxes).bind('keypress', CheckForEnter);
} else {
jQuery(textboxes).bind('keydown', CheckForEnter);
}
});

function SetControlEnterEvent() {
//$(':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');
}
}
XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved