<h1>检测大写锁定键</h1>
<form action="#" method="post">
<p>
<label for="password">密码:</label>
<input type="password" id="password" name="password" /><span style="display:none;">大写锁定键被按下,请注意大小写</span>
</p>
</form>
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
var isShift = e.shiftKey ||(keyCode == 16 ) || false ; // shift键是否按住
if (
((keyCode >= 65 && keyCode <= 90 ) && !isShift) // Caps Lock 打开,且没有按住shift键
|| ((keyCode >= 97 && keyCode <= 122 ) && isShift) // Caps Lock 打开,且按住shift键
) {
oTip.style.display = '';
} else {
oTip.style.display = 'none';
}
}
document.getElementById('password').onkeypress = detectCapsLock;