Home  >  Article  >  Web Front-end  >  jQuery: The use and definition of keypress events

jQuery: The use and definition of keypress events

黄舟
黄舟Original
2017-06-27 14:00:041879browse

Overview

Trigger keypress for each matching elementEvent

This function will call and execute all functions bound to the keydown event, including the browser's default Behavior. You can prevent triggering the browser's default behavior by returning false in a bound function. The keydown event will trigger when the keyboard is pressed.

Parameters

fnFunctionV1.0

The handler function bound in the keypress event of each matching element.

[data],fnString,FunctionV1.4.3

data:keypress([Data], fn) Data can be passed in for function fn to process.

fn: The handler function bound in the keypress event of each matching element.

Example

Description:

Count the number of key presses in the input field:

jQuery Code:

$("input").keydown(function(){  $("span").text(i+=1);});

Example

Count the number of key presses in the input field:

$("input").keydown(function(){
  $("span").text(i+=1);
});

Definition and usage

The keypress event is similar to the keydown event. This event occurs when the button is pressed. It happens on the element that currently has focus.

However, unlike the keydown event, the keypress event occurs every time a character is inserted.

The keypress() method triggers the keypress event, or specifies a function to run when the keypress event occurs.

Note: If set on a document element, this event will occur regardless of whether the element has focus.

Trigger keypress event

Syntax

$(selector).keypress()

The above is the detailed content of jQuery: The use and definition of keypress events. For more information, please follow other related articles on the PHP Chinese website!

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