Implementation of Enter key to switch focus based on Jquery_jquery
Next, we use Jquery to implement the Enter key to switch focus. This code has been tested in common browsers IE7, IE8, Firefox 3, Chrome 2 and Safari 4.
The development tool used is Microsoft VS2010 Jquery framework.
The implementation steps are as follows
1. First reference the Jquery class library
2. Javascript code
Analysis:
$('input:text:first').focus( ; .bind('keydown', function (e) {}
Bind the 'keydown' event to the text box collection
var key = e.which;
Get the currently pressed key value, such as Enter Key value = 13
e.preventDefault();
can prevent its default behavior from happening and other things happen. Here we prevent PostBack from happening, but switch the focus. Another similar method is stopPropagation. It plays the role of preventing js events from bubbling.
The event proxy uses two features that are often ignored in JavaSciprt events: event bubbling and target elements when an event on an element is triggered, such as a mouse. When a button is clicked, the same event will be triggered in all ancestor elements of that element. This process is called event bubbling; the event bubbles up from the original element to the top of the DOM tree. For any event, the target element is the original element, which in our case is the button. Target Element It appears as an attribute in our event object. Using an event proxy, we can add an event handler to an element, wait for the event to bubble up from its child elements, and easily determine which element the event started from.
var nxtIdx = $inp.index(this) 1;
The next element index in the retrieved element set inp
$(":input:text:eq(" nxtIdx ")").focus ();
Position focus to the next element of the collection
3. HTML code
Copy code
Analysis: stored on the page Four text boxes
3. Run the program
If there is a TextArea element on the page, how can we use Enter to switch focus? There are ways. The following fully utilizes some features of Jquery.

Copy code
Analysis:
All TextBoxes in the page refer to Class="cls" to facilitate later Jquery query of page elements.
5. Javascript code
Copy code
Analysis:
var $inp = $('.cls');
The style taken is to assign all elements of cls to the variable inp
6. Operation effect

Author: Smart Life

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



While updating Windows 11 or upgrading from Windows 10 to Windows 11, you may encounter the error Wecouldnotupdatesystemreservedpartition. This may be accompanied by error code 0xc1900104, 0x800f0922 or 0xc1900201. What causes system reserved partition error? This may be caused by a full System Reserved Partition (SRP) that can no longer be written to. Additionally, some third-party security and antivirus applications write to the SRP and can fill it up quickly. Dual booting with Linux can also be the cause of this error. Additionally, if you

The best Windows 11 optional features let you take advantage of your PC's vast potential. You can activate productivity features and get more features. So it can be annoying to suddenly see these settings blank when you need them. Certain features go blank, ranging from faulty system settings to missing and corrupted files. Whatever the cause, we've collected seven simple yet effective fixes to help you restore Windows 11 optional features. Why is the Windows Features box empty? There are many reasons why the Windows 11 optional features box is empty. Here are some popular ones: Setup errors. The component store containing information about Windows functionality is corrupted. Corrupted system files. How to use Windows

Unfortunately, changing basic settings on your Windows device, such as brightness and volume, can be a bit cumbersome. To reach these mundane settings, users have to navigate several menus, which is rather unintuitive. Thankfully, Windows provides a tool that allows users to access and change these mundane settings with the click of a finger. The problem is that few people know it exists. And those who do may not know how to enable it. What is Windows Mobility Center? First introduced in Windows Vista, Windows Mobility Center or WMC is a built-in Windows component that centralizes the most relevant information and settings for portable and mobile devices. some of them

WindowsMediaPlayer is used to play audio and video files. But sometimes when you try to open an mp3 or mp4 file using Windows Media Player, it gives an error message stating that server execution failed. Therefore, you cannot continue. Isn't it annoying? But don't worry this problem can be solved. In this article, we have some solutions you can try to get rid of the error. let's start! Steps to Backup Windows Media Player Files Before applying any solution, it is best to back up the relevant files or folders. Now let us see how to backup Windows Media Player files Please Note: Backup is optional if you need to have all the playlists and profiles

enter is on the right side of the main keyboard area, above the Shift key; the enter key is the enter key, also known as the confirmation key and the input key; there is a key with the word Enter or return on the computer keyboard, which is called the "enter key" ", where Enter is the name of Windows system, and it is called return in macOS.

When any patch is released or any feature is introduced, it is important to update the system frequently. If we don't do this, then we miss out on critical bug fixes, weak security, software incompatibilities, and more. The system might just be acting strange, or the program might simply crash. Normally, we update the system by browsing settings and update and security and then check if there are any updates available. How else can you update if you can't access settings or update and security options? Probably few of us have this problem but the solution is simple and can also be done using PowerShell commands. In this article, let us learn how to manually update Windows 10 system using PowerShell commands. Use PowerS

Enter is the Enter key; there is a key with the word Enter or Return on the computer keyboard, which is called the "Enter key". Enter is the name of the Windows system, and it is called return in macOS, and some Windows computers The enter key will have a curved arrow; the enter key has two functions, namely: 1. Confirming the entered execution command; 2. Functioning as a line break in word processing.

Vue is a very powerful JavaScript framework that can easily help us build interactive web applications. Vue provides some very convenient features, including event modifiers. Event modifiers are a way to simplify DOM event binding and provide us with a way to quickly handle specific events. In Vue, we can bind events by using the v-on directive. The v-on directive allows us to listen for specific events and trigger event handlers. For common DOM things
