Event Altkey,ctrlkey,shiftkey attribute Resolution _javascript Tips

Source: Internet
Author: User

Event.altkey
Function: Detects whether the ALT key is held down when an event occurs.

Syntax: Event.altkey

Take Value: TRUE | False

Description

The Altkey property is true to indicate that the ALT key was pressed and persisted when the event occurred, and that the ALT key was not pressed.
The Altkey property can be used with the mouse or keyboard, and is used to make some quick operation methods.

Event.ctrlkey
Function: Detects if the CTRL key is being held down when an event occurs.

Syntax: Event.ctrlkey

Take Value: TRUE | False

Description

The Ctrlkey property is true to indicate that the CTRL key was pressed and persisted when the event occurred, and that the CTRL key was not pressed as false.
The Ctrlkey property can be used with the mouse or keyboard, and is used to make some quick operation methods.

Event.shiftkey
Function: Detects if the SHIFT key is being held down when an event occurs.

Syntax: Event.shiftkey

Take Value: TRUE | False

Description

The Shiftkey property is true to indicate that the SHIFT key was pressed and persisted when the event occurred, false and the SHIFT key was not pressed.
The Shiftkey property can be used with the mouse or keyboard, and is used to make some quick operation methods.

Instance 1
Example of a combination operation.

Copy Code code as follows:

<input id= "Txt1" type= "text" value= "Hello world!" onclick= "CheckAlt (event)"/>

<script type= "Text/javascript" >
function CheckAlt (oevent)
{
if (Oevent.altkey)
document.getElementById ("Txt1"). Select ();
}
</script>


The effect of this code is:

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

Instance 2
Example of a combination operation.

Copy Code code as follows:

<input id= "Txt2" type= "text" value= "Hello world!" onclick= "cleartext (event)"/>

<script type= "Text/javascript" >
function cleartext (oevent)
{
if (Oevent.ctrlkey && oevent.keycode==46)
document.getElementById ("Txt2"). Value = "";
}
</script>


The effect of this code is:

Use the Ctrl+del key to clear the contents of the text box above. (You must first get the focus of the text box.) This example applies only to IE browsers. )

Instance 3
Example of a combination operation.

Copy Code code as follows:

<div id= "box" style= "width:50px; HEIGHT:25PX;BORDER:1PX solid black; Background-color:red "onclick=" SetColor (event) ></div>

<script type= "Text/javascript" >
var B = true;
function SetColor (oevent)
{
if (Oevent.shiftkey && b)
document.getElementById ("box"). Style.backgroundcolor = "Blue";
if (Oevent.shiftkey &&!b)
document.getElementById ("box"). Style.backgroundcolor = "Red";
b =!b;
}
</script>


The effect of this code is:

Press the SHIFT key and click on the top color block to change the color

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.