This blog is meant for my personal reference and keeping track of what I have learnt. Most articles are found through search engines, if you are the author of the article and would like to remove from this blog, please contact me.
Monday, March 19, 2012
Detect Caps Lock with JavaScript
function capLock(e){
kc = e.keyCode?e.keyCode:e.which;
sk = e.shiftKey?e.shiftKey:((kc == 16)?true:false);
if(((kc >= 65 && kc <= 90) && !sk)||((kc >= 97 && kc <= 122) && sk))
document.getElementById('capsLockWarning').style.visibility = 'visible';
else
document.getElementById('capsLockWarning').style.visibility = 'hidden';
}
Using the script:
<input type="password" name="password" size="20" onkeypress="capLock(event)"><span id="capsLockWarning" style="visibility:hidden"> Caps Lock is on. </span>
Labels:
JavaScript
Subscribe to:
Post Comments (Atom)
css html网页设计代码示例
ReplyDeleteLi标签列表样式类型无显示内联html示例