index.html 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <link rel="stylesheet" href="css/style.css">
  7. <title>Document</title>
  8. </head>
  9. <body>
  10. <div class="container">
  11. <div class="green">congratulations</div>
  12. <form>
  13. <input type="text" placeholder="Login" id="login-name">
  14. <input type="text" placeholder="Password" id="login-password">
  15. <button type="button">
  16. submit
  17. </button>
  18. </form>
  19. <div class="red">failed</div>
  20. </div>
  21. <script>
  22. let login = {};
  23. login.name = "admin"
  24. login.password = "qwerty"
  25. let loginNameIn = document.querySelector("#login-name");
  26. let loginPasswordIn = document.querySelector('#login-password');
  27. let button = document.querySelector('button');
  28. let greenBlock = document.querySelector('.green');
  29. let redBlock = document.querySelector('.red');
  30. function showGreenBlock() {
  31. greenBlock.classList.toggle('active');
  32. }
  33. function showRedBlock() {
  34. redBlock.classList.toggle('active');
  35. }
  36. button.onclick = function() {
  37. let loginNameOut = loginNameIn.value;
  38. let loginPasswordOut = loginPasswordIn.value;
  39. if((login.name == loginNameOut) && (login.password == loginPasswordOut)) {
  40. showGreenBlock();
  41. }else {
  42. showRedBlock();
  43. }
  44. }
  45. </script>
  46. <!-- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> -->
  47. </body>
  48. </html>