search
HomeWeb Front-endJS TutorialEnter to tab focus switching effect code based on Jquery (Enter To Tab)_jquery

第一种方法:

复制代码 代码如下:

$(document).ready(function () {
$(':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 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');
}
}

方法二(转载网络)
复制代码 代码如下:

document.onkeydown = function(evt) {
var isie = (document.all) ? true : false;
var key;
var srcobj;
alert(isie);
if (isie) {
key = event.keyCode;
srcobj = event.srcElement;
}
else {
alert(evt);
key = evt.which;
srcobj = evt.target;
}
if (key == 13 && srcobj.type != 'button' && srcobj.type != 'submit' && srcobj.type != 'reset' && srcobj.type != 'textarea' && srcobj.type != '') {
if (isie) {
event.keyCode = 9;
}
else {
var el = getNextElement(evt.target);
if (el.type != 'hidden')
el.focus();
else
while (el.type == 'hidden')
el = getNextElement(el);
el.focus();
return false;
}
}
}
document.onkeyup = function(evt) {
var isie = (document.all) ? true : false;
var key;
var srcobj;
alert(isie);
if (isie) {
key = event.keyCode;
srcobj = event.srcElement;
}
else {
alert(evt);
key = evt.which;
srcobj = evt.target;
}
if (key == 13 && srcobj.type != 'button' && srcobj.type != 'submit' && srcobj.type != 'reset' && srcobj.type != 'textarea' && srcobj.type != '') {
if (isie) {
event.keyCode = 9;
}
else {
var el = getNextElement(evt.target);
if (el.type != 'hidden')
el.focus();
else
while (el.type == 'hidden')
el = getNextElement(el);
el.focus();
return false;
}
}
}
function getNextElement(field) {
var form = field.form;
for (var e = 0; e if (field == form.elements[e])
break;
}
return form.elements[ e % form.elements.length];
}

function document.onkeydown() {
var e = event.srcElement;
if (event.keyCode == 13 && e.tagName == "INPUT" && e.type == "text")
event.keyCode = 9;
}
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
解决CentOS7的Tab键无法补全命令问题解决CentOS7的Tab键无法补全命令问题Jan 17, 2024 pm 01:30 PM

今天在centOS上做实验,发现之前在Ubuntu下使用的比较习惯的tab键补全命令的方式不能使用,于是非常好奇,经过查找资料并亲自测试,将可行的解决方式记录如下:1)首先需要在终端中运行如下命令:#yuminstallbash-completion//也可以使用通配符安装:yuminstallbash-c*或者你可以安装一些初始化的包组yum-ygroupinstallBaseCompatibilitylibrariesDebuggingToolsDial-upNetworkingsupppo

Vue 中如何实现 tab 组件及多标签页?Vue 中如何实现 tab 组件及多标签页?Jun 25, 2023 am 09:33 AM

随着前端技术的不断更新,Vue作为一款流行的前端框架,已经成为很多开发者的首选。在实际项目中,常常需要使用tab组件以及多标签页来实现不同功能模块的切换和管理。在本文中,我们将介绍如何利用Vue实现一个简单的tab组件以及多标签页。一、实现一个简单的tab组件创建Tab.vue组件在项目中创建一个Tab.vue的组件,用于显示ta

java怎么读取回车java怎么读取回车Mar 22, 2024 pm 04:57 PM

在 Java 中,回车通常由换行符表示。Windows 系统中使用 "\r\n" 表示回车换行,而 Unix/Linux 系统中则使用 "\n"。读取包含回车的文本时,Java将这些字符视为普通字符。可以使用 BufferedReader 或 Scanner 类从输入流中读取文本,直到遇到回车换行符。

vue实现tab三种方式是什么vue实现tab三种方式是什么Jan 29, 2023 pm 02:49 PM

vue实现tab三种方式:1、通过“v-show”控制tab内容切换;2、通过vue中is的特性和“keep-alive”缓存实现tab切换;3、通过“router-link”实现路由切换。

java怎样用回车继续输入java怎样用回车继续输入Mar 25, 2024 am 10:23 AM

在 Java 中,Scanner 类可用于实现回车继续的功能。该类从标准输入中读取用户输入。以下示例展示了如何使用 Scanner 类实现此功能: ```java import java.util.Scanner; public class ContinueOnEnter { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); Syste

alt+tab切换不了界面什么原因alt+tab切换不了界面什么原因Mar 09, 2023 pm 02:11 PM

alt+tab切换不了界面的原因是此命令被禁用,其解决办法:1、打开电脑,点击开始菜单,选择运行指令;2、在开始右侧的空白栏中输入“regedit”后,点击确定;3、进入到注册表管理器,找到“AltTabSettings”选项;4、双击“AltTabSettings”,在打开的选项中修改数值数据为“00000001”,点击“确认”即可。

Win10检测出威胁但清除不掉怎么办Win10检测出威胁但清除不掉怎么办Feb 20, 2024 am 08:06 AM

近期有用户报告在对系统进行安全扫描时发现一些无法清除的威胁。这可能是由于恶意软件采取了隐蔽的手段,导致清除困难。解决此问题的方法包括更新杀毒软件、使用安全模式运行扫描、手动清除威胁等。建议尝试不同的方法,或者寻求专业帮助,以确保系统的安全性。解决方法:1、”win+R”快捷键开启运行,输入”regedit”回车打开。2、进入到注册表编辑器界面后,将”HKEY_LOCAL_MACHINESoftwarePoliciesMicrosoftWindow

RedMagic reveals more specs of its new gaming tabletRedMagic reveals more specs of its new gaming tabletSep 01, 2024 am 06:34 AM

The second RedMagic gaming tablet will be fully unveiled on September 5. A recent benchmark run on AnTuTu revealed that it will feature the Snapdragon 8 Gen 3 Leading Version, making it as capable as the company’s latest Android smartphone, the 9S Pr

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use