example17.html 917 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title></title>
  6. </head>
  7. <body>
  8. <form id="login" action="" method="post">
  9. <p>
  10. <input type="text" name="username" placeholder="请输入用户名">
  11. <span style="color: red; font-size: 12px"></span>
  12. </p>
  13. <p>
  14. <input type="password" name="password" placeholder="请输入口令">
  15. </p>
  16. <p>
  17. <input type="submit" value="登录">
  18. </p>
  19. </form>
  20. <script src="js/jquery.min.js"></script>
  21. <script>
  22. $(function() {
  23. $('input:first').val(localStorage.uid);
  24. $('#login').on('submit', function(evt) {
  25. evt.preventDefault();
  26. var username = $('input:first').val();
  27. if (/^[a-zA-Z][a-zA-Z0-9_]{5,19}$/.test(username)) {
  28. localStorage.uid = username;
  29. evt.target.submit();
  30. } else {
  31. $('input:first').next().text('请输入有效的用户名');
  32. }
  33. });
  34. });
  35. </script>
  36. </body>
  37. </html>