Home > Web Front-end > JS Tutorial > jquery enter key trigger event implementation method

jquery enter key trigger event implementation method

小云云
Release: 2018-01-16 09:27:20
Original
2696 people have browsed it

This article mainly shares with you an example of how jquery implements the enter key trigger event. It has a good reference value and I hope it will be helpful to everyone. Let’s follow the editor to take a look, I hope it can help everyone.

There are 3 keyboard events:

keydown, keypress, keyup, which are respectively pressing, pressing without lifting, and lifting the keyboard.

The correct code is:

$(document).keyup(function(event){
 if(event.keyCode ==13){
  $("#submit").trigger("click");
 }
});
Copy after login

Recommended: keyup to prevent the laptop keyboard from being accidentally touched

1. Some documents have it written like this:

$(window).keydown(function(){
...
})
Copy after login

It is unsuccessful under IE6 under XP system.

2. There is also INPUT's

$("input").keydown(function(){
...
})
Copy after login

In this case, keyboard events can only be monitored when the input gets focus.

Related recommendations:

JQuery simulates click events and automatically triggers events

How to implement mouse hovering after a certain period of time in js Trigger event

JQuery-based select drop-down box selection trigger event instance analysis

The above is the detailed content of jquery enter key trigger event implementation method. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template