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