Use JavaScript to check whether the uppercase key (Caps Lock) is open script _javascript tips

Source: Internet
Author: User
Tags visibility javascript keycode
Is there a capital letter in the password when the user encounters a page that needs to be entered with a password? Does the capital key (Caps Lock) open? Wouldn't it be better if you could give the user a hint?

The following example code gives the method, and there are comments in the necessary description code.
Ask the knowledge point: Event.keycode and Event.shiftkey

Code

<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" > <HTML> <HEAD> <TITLE> detect C APS Lock </TITLE> <script> function Detectcapslock (e) {valuecapslock = E.keycode? e.keycode:e.w Hich Does Caps Lock open valueshift = E.shiftkey? E.shiftkey: ((valuecapslock = 16)? True:false); Shift key Hold if ((Valuecapslock >= && valuecapslock <=) &&! Valueshift) Caps Lock is turned on and the SHIFT key is not held down | | ((Valuecapslock >= && valuecapslock <= 122) && Valueshift)) Caps Lock opens, and hold down the SHIFT key document.getElementById (' Capstatus '). style.visibility = ' visible '; else document.getElementById (' Capstatus '). style.visibility = ' hidden '; /* JavaScript keycode code corresponding table event.keycode=32 space event.keycode=13 carriage return event.keycode=27 ESC event.keycode=16) Shift event.keycode=17) Ctrl event.keycode=18) Alt/} </script> </HEAD> <BODY> <input Type = "Password" name = "pwd" onkeypress = "Detectcapslock (event)"/> <div id = "Capstatus" style = "Visibili" Ty:hidden "><font color =red> Caps Lock is on. <font></div> </BODY> </HTML>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]


Original: http://www.blogjava.net/majianan/archive/2007/02/01/97284.html
Related Article

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.