Advertisement
Guest User

Untitled

a guest
Sep 9th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.09 KB | None | 0 0
  1. function capLock(e){
  2. var kc = e.keyCode ? e.keyCode : e.which;
  3. var sk = e.shiftKey ? e.shiftKey : kc === 16;
  4. var visibility = ((kc >= 65 && kc <= 90) && !sk) ||
  5. ((kc >= 97 && kc <= 122) && sk) ? 'visible' : 'hidden';
  6. document.getElementById('divMayus').style.visibility = visibility
  7. }
  8.  
  9. <input type="password" name="txtPassword" onkeypress="capLock(event)" />
  10. <div id="divMayus" style="visibility:hidden">Caps Lock is on.</div>
  11.  
  12. $(document).ready(function() {
  13.  
  14. /*
  15. * Bind to capslockstate events and update display based on state
  16. */
  17. $(window).bind("capsOn", function(event) {
  18. $("#statetext").html("on");
  19. });
  20. $(window).bind("capsOff", function(event) {
  21. $("#statetext").html("off");
  22. });
  23. $(window).bind("capsUnknown", function(event) {
  24. $("#statetext").html("unknown");
  25. });
  26.  
  27. /*
  28. * Additional event notifying there has been a change, but not the state
  29. */
  30. $(window).bind("capsChanged", function(event) {
  31. $("#changetext").html("changed").show().fadeOut();
  32. });
  33.  
  34. /*
  35. * Initialize the capslockstate plugin.
  36. * Monitoring is happening at the window level.
  37. */
  38. $(window).capslockstate();
  39.  
  40. // Call the "state" method to retreive the state at page load
  41. var initialState = $(window).capslockstate("state");
  42. $("#statetext").html(initialState);
  43.  
  44. });
  45.  
  46. $(document).ready(function() {
  47.  
  48. /*
  49. * Bind to capslockstate events and update display based on state
  50. */
  51. $(window).bind("capsOn", function(event) {
  52. if ($("#Passwd:focus").length > 0) {
  53. $("#capsWarning").show();
  54. }
  55. });
  56. $(window).bind("capsOff capsUnknown", function(event) {
  57. $("#capsWarning").hide();
  58. });
  59. $("#Passwd").bind("focusout", function(event) {
  60. $("#capsWarning").hide();
  61. });
  62. $("#Passwd").bind("focusin", function(event) {
  63. if ($(window).capslockstate("state") === true) {
  64. $("#capsWarning").show();
  65. }
  66. });
  67.  
  68. /*
  69. * Initialize the capslockstate plugin.
  70. * Monitoring is happening at the window level.
  71. */
  72. $(window).capslockstate();
  73.  
  74. });
  75.  
  76. <html>
  77. <head>
  78. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
  79. <script language="Javascript">
  80. $(document).ready(function(){
  81. $('input').keypress(function(e) {
  82. var s = String.fromCharCode( e.which );
  83.  
  84. if((s.toUpperCase() === s && s.toLowerCase() !== s && !e.shiftKey) ||
  85. (s.toUpperCase() !== s && s.toLowerCase() === s && e.shiftKey)){
  86. if($('#capsalert').length < 1) $(this).after('<b id="capsalert">CapsLock is on!</b>');
  87. } else {
  88. if($('#capsalert').length > 0 ) $('#capsalert').remove();
  89. }
  90. });
  91. });
  92. </script>
  93. </head>
  94. <body>
  95. <label style="float:left;display:block;width:80px;">Login:</label><input type="text" /><br />
  96. <label style="float:left;display:block;width:80px;">Password:</label><input type="password" /><br />
  97. </body>
  98.  
  99. <html><head><title>Checking Caps Lock using Jquery - Javascript</title></head>
  100. <body>
  101. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
  102. <form action="/codes/capslock.html" id="formid">
  103.  
  104. <div>
  105. User:
  106. </div>
  107. <div>
  108. <input type="text" id="user" />
  109. </div>
  110.  
  111. <div>
  112. Password:
  113. </div>
  114. <div>
  115. <input type="password" id="password" />
  116. </div>
  117.  
  118. <div id="capslockdiv" style="display: none; color: red;">
  119. Caps Lock On
  120. </div>
  121.  
  122. <div>
  123. <input type="submit" />
  124. </div>
  125. </form>
  126. <script>
  127. $(document).ready(
  128. function () {
  129. check_capslock_form($('#formid')); //applies the capslock check to all input tags
  130. }
  131. );
  132.  
  133. document.onkeydown = function (e) { //check if capslock key was pressed in the whole window
  134. e = e || event;
  135. if (typeof (window.lastpress) === 'undefined') { window.lastpress = e.timeStamp; }
  136. if (typeof (window.capsLockEnabled) !== 'undefined') {
  137. if (e.keyCode == 20 && e.timeStamp > window.lastpress + 50) {
  138. window.capsLockEnabled = !window.capsLockEnabled;
  139. $('#capslockdiv').toggle();
  140. }
  141. window.lastpress = e.timeStamp;
  142. //sometimes this function is called twice when pressing capslock once, so I use the timeStamp to fix the problem
  143. }
  144.  
  145. };
  146.  
  147. function check_capslock(e) { //check what key was pressed in the form
  148. var s = String.fromCharCode(e.keyCode);
  149. if (s.toUpperCase() === s && s.toLowerCase() !== s && !e.shiftKey) {
  150. window.capsLockEnabled = true;
  151. $('#capslockdiv').show();
  152. }
  153. else {
  154. window.capsLockEnabled = false;
  155. $('#capslockdiv').hide();
  156. }
  157. }
  158.  
  159. function check_capslock_form(where) {
  160. if (!where) { where = $(document); }
  161. where.find('input,select').each(function () {
  162. if (this.type != "hidden") {
  163. $(this).keypress(check_capslock);
  164. }
  165. });
  166. }
  167. </script>
  168.  
  169. </body>
  170. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement