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