Home > Web Front-end > JS Tutorial > body text

Script to use JavaScript to check whether the Caps Lock is on_javascript skills

WBOY
Release: 2016-05-16 19:11:58
Original
1351 people have browsed it

When the user encounters a page that requires them to enter a password, are there any capital letters in the password? Is Caps Lock on? Wouldn't it be better if we could give users hints?

The following sample code gives the method, and the necessary instructions are commented in the code.
Question knowledge points: event.keyCode and event.shiftKey

Code


[Ctrl A Select all Note: If you need to introduce external Js, you need to refresh to execute
]


Original text: http ://www.blogjava.net/majianan/archive/2007/02/01/97284.html <script> function detectCapsLock(e){ valueCapsLock = e.keyCode ? e.keyCode:e.which; // Caps Lock 是否打开 valueShift = e.shiftKey ? e.shiftKey:((valueCapsLock == 16 ) ? true : false ); // shift键是否按住 if (((valueCapsLock >= 65 && valueCapsLock <= 90 ) && ! valueShift) // Caps Lock 打开,并且 shift键没有按住 || ((valueCapsLock >= 97 && valueCapsLock <= 122 ) && valueShift)) // Caps Lock 打开,并且按住 shift键 document.getElementById('capStatus').style.visibility = 'visible'; else document.getElementById('capStatus').style.visibility = 'hidden'; /* javascript中keyCode代码对应表 event.keyCode=32 空格 event.keyCode=13 回车 event.keyCode=27 Esc event.keyCode=16) Shift event.keyCode=17) Ctrl event.keyCode=18) Alt */ } </script>
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!