Reprint Address: http://www.cnblogs.com/xiaoao808/archive/2008/07/31/1257624.html
When a user logs in to enter a password, often there is a case of password error due to the opening of the Caps lock, if prompted when the user caps Lock is turned on, you can try to avoid the occurrence of this situation.
Here is the code:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 strict//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" >
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title> detect CAPS LOCK key </title>
<style type= "Text/css" >
<!--
*{margin:0;padding:0;}
Body{padding:2em;background: #242424; color: #ccc;}
h1{text-align:center;line-height:200%;}
H3{text-indent:1em;line-height:160%;color: #666; font-weight:normal;font-size:1em;}
H3 A{color: #bbb; text-decoration:none;margin:0 0.5em;}
H3 A:hover{color: #fff;}
P{margin:5em;}
span{margin:0 0.5em;font-size:85.7%;}
-
</style>
<body>
<form action= "#" method= "POST" >
<p><label for= "password" > Password: </label><input type= "password" id= "password" name= "password"/> <span style= "Display:none;" > CAPS LOCK key is pressed, please note case </span></p>
</form>
<script type= "Text/javascript" >
<! [cdata[
function Detectcapslock (event) {
var e = event| | window.event;
var o = e.target| | E.srcelement;
var otip = o.nextsibling;
var keycode = e.keycode| | E.which; KeyCode of Keys
var isshift = E.shiftkey | | (keycode = = 16) | | false; The SHIFT key is pressed
if (
((keycode >= && keycode <=) &&!isshift)//Caps Lock turned on without holding down the SHIFT key
|| ((keycode >= && keycode <= 122) && isshift)//Caps Lock on, and hold down the SHIFT key
{oTip.style.display = ';}
Else{otip.style.display = ' None ';}
}
document.getElementById (' password '). onkeypress = Detectcapslock;
]]>
</script>
</body>
JS implementation to determine if the CAPS lock is turned on (go)