Home > Web Front-end > JS Tutorial > Event altKey, ctrlKey, shiftKey attribute analysis_javascript skills

Event altKey, ctrlKey, shiftKey attribute analysis_javascript skills

WBOY
Release: 2016-05-16 17:08:43
Original
1159 people have browsed it

event.altKey
Function: Detect whether the Alt key is pressed when the event occurs.

Syntax: event.altKey

Value: true | false

Description:

The altKey attribute is true to indicate that the Alt key was pressed and held when the event occurred, and false to indicate that the Alt key was not pressed.
The altKey attribute can be used in combination with the mouse or keyboard, and is mostly used to create some shortcut operations.

event.ctrlKey
Function: Detect whether the Ctrl key is pressed when the event occurs.

Syntax: event.ctrlKey

Value: true | false

Description:

The ctrlKey attribute is true if the Ctrl key is pressed and held when the event occurs, and false if the Ctrl key is not pressed.
The ctrlKey attribute can be used in conjunction with the mouse or keyboard, and is mostly used to create some shortcut operations.

event.shiftKey
Function: Detect whether the Shift key is pressed when the event occurs.

Syntax: event.shiftKey

Value: true | false

Description:

The shiftKey attribute is true to indicate that the Shift key was pressed and held when the event occurred, and false to indicate that the Shift key was not pressed.
The shiftKey attribute can be used in combination with the mouse or keyboard, and is mostly used to create some shortcut operations.

Example 1
Example of combination operation.

Copy code The code is as follows:



The effect of this code is:

If you hold down the Alt key and click on the text box above, you can select the text in the text box.

Example 2
Example of combination operation.

Copy code The code is as follows:



The effect of this code is:

Use the "Ctrl Del" key combination to clear the contents of the text box above. (The text box must be focused first. This example only applies to IE browser.)

Example 3
Combination operation example.

Copy code The code is as follows:



The effect of this code is:

Hold the "Shift" key and click on the color block above with the mouse to change the color of the color block

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