JS實現(xiàn)Enter鍵跳轉(zhuǎn)及控件獲得焦點
更新時間:2013年08月12日 18:03:37 作者:
想讓Enter鍵跳轉(zhuǎn)的同時讓控件獲得焦點,具體實現(xiàn)js代碼如下,感興趣的朋友可以參考下,希望對大家有所幫助
復(fù)制代碼 代碼如下:
//回車跳轉(zhuǎn)
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');
}
}
相關(guān)文章
JavaScript實現(xiàn)文件下載的14種方法總結(jié)大全
在JavaScript中實現(xiàn)文件下載的功能可以通過多種方式實現(xiàn),這篇文章主要給大家介紹了關(guān)于JavaScript實現(xiàn)文件下載的14種方法,文中通過代碼介紹的非常詳細,需要的朋友可以參考下2024-07-07
JS實現(xiàn)點擊文字對應(yīng)DIV層不停閃動效果的方法
這篇文章主要介紹了JS實現(xiàn)點擊文字對應(yīng)DIV層不停閃動效果的方法,實例分析了javascript操作div層的效果,非常實用,具有一定參考借鑒價值,需要的朋友可以參考下2015-03-03

