Home Web Front-end JS Tutorial How to use keyboard events in jquery

How to use keyboard events in jquery

Apr 19, 2018 pm 02:44 PM
jquery event keyboard

This time I will show you how to use keyboard events in jquery, and what are the precautions for using keyboard events in jquery, The following is a practical case, let’s take a look.

jQuery has three functions to handle keyboard events. According to the order in which the events occur, they are:

jquery code:

1. keydown();
2. keyup();
3. keypress();

keydown()

The keydown event will be triggered when the keyboard is pressed. You can return false in the bound function to prevent the browser's default event from being triggered.

keyup()

The keyup event will be triggered when the key is released, that is, the event after you press the keyboard and get up.

keypress()

The keypress event is triggered when a key is tapped. We can understand it as pressing and lifting the same key.

Keyboard events can pass a parameter event. In fact, some jQuery event functions can pass such a parameter:

jquery code:

$('input').keydown(function(event){  
    alert(event.keyCode);  
});
Copy after login

In the above code, event.keyCode can help us get what key we pressed. It returns the ASCII code, such as the up, down, left and right keys, which are 38, 40, 37, 39 respectively

If we want to implement ctrl Enter, it is ctrl Enter to submit the form

$(document).keypress(function(e) {  
   if (e.ctrlKey && e.which == 13)
   $("form").submit();  
}) ;
Copy after login

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the PHP Chinese website!

Recommended reading:



The above is the detailed content of How to use keyboard events in jquery. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
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

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 Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Two Point Museum: All Exhibits And Where To Find Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

VGN co-branded 'Elden's Circle' keyboard and mouse series products are now on the shelves: Lani / Faded One custom theme, starting from 99 yuan VGN co-branded 'Elden's Circle' keyboard and mouse series products are now on the shelves: Lani / Faded One custom theme, starting from 99 yuan Aug 12, 2024 pm 10:45 PM

According to news from this site on August 12, VGN launched the co-branded "Elden Ring" keyboard and mouse series on August 6, including keyboards, mice and mouse pads, designed with a customized theme of Lani/Faded One. The current series of products It has been put on JD.com, priced from 99 yuan. The co-branded new product information attached to this site is as follows: VGN丨Elden Law Ring S99PRO Keyboard This keyboard uses a pure aluminum alloy shell, supplemented by a five-layer silencer structure, uses a GASKET leaf spring structure, has a single-key slotted PCB, and the original height PBT material Keycaps, aluminum alloy personalized backplane; supports three-mode connection and SMARTSPEEDX low-latency technology; connected to VHUB, it can manage multiple devices in one stop, starting at 549 yuan. VGN丨Elden French Ring F1PROMAX wireless mouse the mouse

How to set the skin for the WeChat keyboard How to set the skin for the WeChat keyboard How to set the skin for the WeChat keyboard How to set the skin for the WeChat keyboard Mar 13, 2024 am 09:04 AM

How to set the skin for WeChat keyboard? WeChat Keyboard is a very smart mobile phone input method software. This software has many user-friendly functions. It allows users to choose their own input mode and find the expressions they want as quickly as possible on this software. send out. This software also allows users to change the skin of the keyboard themselves. Many users are not sure how to change the skin. The editor below has compiled the skin changing methods for your reference. How to set the WeChat keyboard skin In WeChat, SMS or other applications that require the use of the keyboard on your phone, you can click the input method settings icon in the upper left corner of the keyboard to enter the settings page to view the function setting options for various input methods. 2. Click "Personalized Skin" on the settings page of the input method.

Maicong K87 three-mode mechanical keyboard adds 'hyacinth axis' and 'ice cream axis' version: Gasket structure, initial price starts at 299 yuan Maicong K87 three-mode mechanical keyboard adds 'hyacinth axis' and 'ice cream axis' version: Gasket structure, initial price starts at 299 yuan Feb 29, 2024 pm 05:00 PM

According to news from this website on February 29, Maicong today launched two versions of "Hyacinth Switch" and "Glazed Ice Cream Switch" for the K87 three-mode mechanical keyboard. The keyboard features "Gasket structure, 80% arrangement", related shaft keyboards The price information is as follows: "Hyacinth Switch" version: initial price is 299 yuan. "Liuguang Ice Cream Switch" version: initial price is 379 yuan. According to reports, the series of keyboards use Gasket structure, 87-key 80% arrangement, full-key rollover, and support thermal For plugging and unplugging, it claims to use "original/MDA two-color PBT keycaps", uses a 1.2mm single-key slotted PCB (lower lamp position), is equipped with RGB lighting effects, and has a magnetic absorption nameplate design. In addition, this keyboard is equipped with a 6000 mAh battery and a wireless delay of 3ms. The official size and size of the keyboard have not been announced.

How to set up handwriting input method on Apple mobile phone keyboard How to set up handwriting input method on Apple mobile phone keyboard Mar 08, 2024 pm 02:30 PM

Apple mobile keyboard users want to set up the handwriting input method, but don’t know how to do it. It’s actually very simple. Users can directly select the handwriting input method in the phone’s keyboard settings. If not, they can also manually add a handwriting input method. How to set the handwriting input method on the Apple mobile phone keyboard A: Enable the handwriting input method directly in the keyboard settings 1. When Apple users use the input method, the handwriting input method is enabled by default. 2. Users only need to click and hold the lower left corner to select the handwriting input method while typing. 3. If the user does not have a handwriting input method in his mobile phone, he can also add it manually. 4. The user enters the settings, finds the universal keyboard settings, and adds the handwriting input option to the first keyboard. 5. Use handwriting input method to

Lingbao K87 / PRO three-mode mechanical keyboard is on sale for the first time: Gasket structure, optional keycap shaft body, starting from 99 yuan Lingbao K87 / PRO three-mode mechanical keyboard is on sale for the first time: Gasket structure, optional keycap shaft body, starting from 99 yuan Jul 20, 2024 am 01:35 AM

According to news from this website on July 19, Lingbao K87/PRO three-mode mechanical keyboard will be on sale at 8 o'clock tonight. The main differences between the two versions are the shaft/color/battery differences. The standard version is equipped with 4000 mAh. Battery, the PRO version is equipped with an 8000 mAh battery. The price information compiled by this website is as follows: K87 Light Cloud White: 99 yuan K87 Night Purple/Xiaguang Purple/Sunny Mountain Blue: 149 yuan K87 Dust Gray/Star Daisy Purple: 199 yuan K87PRO : 249 yuan According to reports, this keyboard adopts a Gasket structure, uses an 80% arrangement layout, is available in a variety of colors, has built-in lower light RGB lights, and supports three-mode connection 2.4G (1KHz)/wired (1KHz)/Bluetooth (125Hz) ). In terms of specifications, series keyboards are optional

Ai Stone launches NA87 MAG 87-key magnetic axis keyboard: Asat structure, 8KHz return rate, 199 yuan Ai Stone launches NA87 MAG 87-key magnetic axis keyboard: Asat structure, 8KHz return rate, 199 yuan Mar 31, 2024 pm 04:41 PM

According to news from this website on March 31, Aitou recently launched an 87-key magnetic axis keyboard model "NA87MAG" on JD.com. The standard price is 219 yuan. If you pay a 10 yuan deposit, you will get an immediate discount of 20 yuan on the final payment. The actual price is 199 yuan. According to reports, this keyboard uses an Asat structure and is claimed to provide "HIFI-level typing sound quality and a consistent tough feel." Users can also adjust the feel of the keyboard by replacing different pads to achieve customization from tough to soft. Switching requirements. In addition, this keyboard is also equipped with a "three-dimensional game inner structure", which is said to be able to concentrate the sound of each key through a single-key closed design in a chessboard format, thereby "achieving three-dimensional sound optimization"; it also has 16.8 million colors of RGB light. Additionally, this keyboard features Le

Keychron launches Q10 Max three-mode mechanical keyboard: 75% Alice configuration, priced starting from 1,238 yuan Keychron launches Q10 Max three-mode mechanical keyboard: 75% Alice configuration, priced starting from 1,238 yuan Mar 08, 2024 am 08:40 AM

According to news from this site on March 7, Keychron today released the Q10Max three-mode mechanical keyboard. The keyboard adopts 75% Alice configuration. The shaft-less keycap kit is priced at 1,238 yuan. The keyboard equipped with Jiadalong’s customized Jupiter shaft and PBT keycaps is priced at 1,358 yuan. It will go on sale at Tmall flagship store at 8 o’clock tonight. The Q10Max mechanical keyboard belongs to the Keychron QMax three-mode "Aluminum Tuo Tuo" series, which has a number of keyboards with different layouts such as Q1/Q2/Q3/Q5/Q6/Q60/Q65Max on the market. ▲ Keychron Q10Max keyboard product features The Q10Max body is made of 6063 aluminum CNC process, using 75% Alice configuration, and the official claims that it “fits the human wrist”

jQuery Tips: Quickly modify the text of all a tags on the page jQuery Tips: Quickly modify the text of all a tags on the page Feb 28, 2024 pm 09:06 PM

Title: jQuery Tips: Quickly modify the text of all a tags on the page In web development, we often need to modify and operate elements on the page. When using jQuery, sometimes you need to modify the text content of all a tags in the page at once, which can save time and energy. The following will introduce how to use jQuery to quickly modify the text of all a tags on the page, and give specific code examples. First, we need to introduce the jQuery library file and ensure that the following code is introduced into the page: &lt

See all articles