JS實(shí)現(xiàn)Enter鍵跳轉(zhuǎn)及控件獲得焦點(diǎn)
更新時(shí)間:2013年08月12日 18:03:37 作者:
想讓Enter鍵跳轉(zhuǎn)的同時(shí)讓控件獲得焦點(diǎn),具體實(shí)現(xiàn)js代碼如下,感興趣的朋友可以參考下,希望對(duì)大家有所幫助
復(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');
}
}
您可能感興趣的文章:
- js 上下左右鍵控制焦點(diǎn)(示例代碼)
- 使用js判斷控件是否獲得焦點(diǎn)
- 通過JS來判斷頁面控件是否獲取焦點(diǎn)
- JS文本獲得焦點(diǎn)清除文本文字的示例代碼
- js 判斷控件獲得焦點(diǎn)的示例代碼
- js/jquery獲取文本框輸入焦點(diǎn)的方法
- js設(shè)置文本框中焦點(diǎn)位置在最后的示例代碼(簡單實(shí)用)
- js實(shí)現(xiàn)文本框中焦點(diǎn)在最后位置
- js實(shí)現(xiàn)獲取焦點(diǎn)后光標(biāo)在字符串后
- js控制輸入框獲得和失去焦點(diǎn)時(shí)狀態(tài)顯示的方法
- js仿土豆網(wǎng)帶縮略圖的焦點(diǎn)圖片切換效果實(shí)現(xiàn)方法
- JS+CSS實(shí)現(xiàn)淡入式焦點(diǎn)圖片幻燈切換效果的方法
- js焦點(diǎn)文字滾動(dòng)效果代碼分享
相關(guān)文章
JavaScript靜態(tài)的動(dòng)態(tài)
JavaScript靜態(tài)的動(dòng)態(tài)...2006-09-09JavaScript+Canvas實(shí)現(xiàn)帶跳動(dòng)效果的粒子動(dòng)畫
這篇文章主要為大家詳細(xì)介紹了如何通過JavaScript和Canvas實(shí)現(xiàn)帶跳動(dòng)效果的粒子動(dòng)畫,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以參考一下2023-03-03用正則表達(dá)式 動(dòng)態(tài)創(chuàng)建/增加css style script 兼容IE firefox
動(dòng)態(tài)創(chuàng)建/增加css style script 用正則表達(dá)式 兼容IE firefox2009-03-03微信小程序使用websocket通訊的demo,含前后端代碼,親測可用
這篇文章主要介紹了微信小程序使用websocket通訊的demo,含前后端代碼,親測可用,需要的朋友可以參考下2019-05-05javascript設(shè)計(jì)模式 – 原型模式原理與應(yīng)用實(shí)例分析
這篇文章主要介紹了javascript設(shè)計(jì)模式 – 原型模式,結(jié)合實(shí)例形式分析了javascript原型模式相關(guān)概念、原理、應(yīng)用場景及操作注意事項(xiàng),需要的朋友可以參考下2020-04-04Javascript中Math.max和Math.max.apply的區(qū)別和用法詳解
這篇文章主要介紹了Javascript中Math.max和Math.max.apply的區(qū)別和用法,本文給大家啊介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-08-08