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+Canvas實現(xiàn)帶跳動效果的粒子動畫
這篇文章主要為大家詳細(xì)介紹了如何通過JavaScript和Canvas實現(xiàn)帶跳動效果的粒子動畫,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以參考一下2023-03-03用正則表達(dá)式 動態(tài)創(chuàng)建/增加css style script 兼容IE firefox
動態(tài)創(chuàng)建/增加css style script 用正則表達(dá)式 兼容IE firefox2009-03-03微信小程序使用websocket通訊的demo,含前后端代碼,親測可用
這篇文章主要介紹了微信小程序使用websocket通訊的demo,含前后端代碼,親測可用,需要的朋友可以參考下2019-05-05javascript設(shè)計模式 – 原型模式原理與應(yīng)用實例分析
這篇文章主要介紹了javascript設(shè)計模式 – 原型模式,結(jié)合實例形式分析了javascript原型模式相關(guān)概念、原理、應(yīng)用場景及操作注意事項,需要的朋友可以參考下2020-04-04Javascript中Math.max和Math.max.apply的區(qū)別和用法詳解
這篇文章主要介紹了Javascript中Math.max和Math.max.apply的區(qū)別和用法,本文給大家啊介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-08-08