JS判断键盘大小写键状态

 1 <script type="text/javascript">
 2             function detectCapsLock(event) {
 3                 var e = event || window.event;
 4                 var o = e.target || e.srcElement;
 5                 var oTip = o.nextSibling;
 6                 var keyCode = e.keyCode || e.which; // 按键的keyCode 
 7                 var isShift = e.shiftKey || (keyCode == 16) || false; // shift键是否按住
 8                 if (
 9                     ((keyCode >= 65 && keyCode <= 90) && !isShift) // Caps Lock 打开,且没有按住shift键 
10                     || ((keyCode >= 97 && keyCode <= 122) && isShift)// Caps Lock 打开,且按住shift键
11                 ) {
12                     oTip.style.display = '';
13                 }
14                 else {
15                     oTip.style.display = 'none';
16                 }
17             }
18  
19             window.onload = function () {
20                 document.getElementById('<%= txtUserName.ClientID %>').focus();
21                 document.getElementById('<%= txtPassword.ClientID %>').onkeypress = detectCapsLock;
22             };
23 </script>

 

你可能感兴趣的:(大小写)