Event Altkey,ctrlkey,shiftkey Property Resolution

Source: Internet
Author: User

  This article is mainly on the event Altkey,ctrlkey,shiftkey attribute analysis of detailed analytical introduction, the need for friends can come to the reference, I hope to help you.

event.altkey  function: Detects whether the ALT key was pressed when the event occurred.   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 False if the ALT key was not pressed.   Altkey properties can be combined with a mouse or keyboard, used to make some quick operation.     event.ctrlkey  function: To detect if the CTRL key was pressed while the event occurred.   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 the CTRL key was not pressed as false.   Ctrlkey properties can be combined with a mouse or keyboard, used to make some quick operation.     event.shiftkey  function: Detects if the SHIFT key is being pressed while the 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.   Shiftkey properties can be combined with a mouse or keyboard, used to make some quick operation.       Instance 1  combined Operation example.   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 click the text box above, you canSelect the text in the text box.     Instance 2  combined Operation example.   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)   &nbs P 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  combined Operation example.   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>    &nbsp The effect of this code is:   Hold down the "Shift" button and click on the top of the color block, you can change color block 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.