手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >JS实现Enter键跳转及控件获得焦点
JS实现Enter键跳转及控件获得焦点
摘要:复制代码代码如下://回车跳转jQuery(document).ready(function(){//$(':input:text:firs...

复制代码 代码如下:

//回车跳转

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实现Enter键跳转及控件获得焦点】相关文章:

jquery插件validation实现验证身份证号等

JavaScript实现Iterator模式实例分析

Nodejs实现批量下载妹纸图

JavaScript实现身份证验证代码

JQuery中DOM实现事件移除的方法

JS或jQuery获取ASP.NET服务器控件ID的方法

JS实现两表格里数据来回转移的方法

js+cookies实现悬浮购物车的方法

基于JavaScript实现智能右键菜单

JavaScript实现表格点击排序的方法

精品推荐
分类导航