login.html 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>登录页面</title>
  6. <script src="js/jquery-2.1.4.min.js"></script>
  7. <style>
  8. /* 全局样式重置 */
  9. * {
  10. margin: 0;
  11. padding: 0;
  12. box-sizing: border-box;
  13. font-family: "Microsoft YaHei", sans-serif;
  14. }
  15. /* 页面背景 */
  16. body {
  17. background-color: #f5f5f5;
  18. display: flex;
  19. justify-content: center;
  20. align-items: center;
  21. min-height: 100vh;
  22. }
  23. /* 登录表单容器 */
  24. .login-container {
  25. background-color: #ffffff;
  26. padding: 30px 40px;
  27. border-radius: 8px;
  28. box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  29. width: 100%;
  30. max-width: 400px;
  31. }
  32. /* 表单标题 */
  33. .login-title {
  34. text-align: center;
  35. font-size: 24px;
  36. color: #333;
  37. margin-bottom: 25px;
  38. font-weight: 600;
  39. }
  40. /* 输入项样式 */
  41. .form-item {
  42. margin-bottom: 20px;
  43. }
  44. /* 标签样式 */
  45. .form-item label {
  46. display: block;
  47. margin-bottom: 8px;
  48. color: #666;
  49. font-size: 14px;
  50. }
  51. /* 输入框样式 */
  52. .form-item input {
  53. width: 100%;
  54. height: 40px;
  55. padding: 0 10px;
  56. border: 1px solid #ddd;
  57. border-radius: 4px;
  58. font-size: 14px;
  59. transition: border-color 0.3s;
  60. }
  61. /* 输入框聚焦样式 */
  62. .form-item input:focus {
  63. outline: none;
  64. border-color: #409eff;
  65. box-shadow: 0 0 5px rgba(64, 158, 255, 0.2);
  66. }
  67. /* 登录按钮样式 */
  68. .login-btn {
  69. width: 100%;
  70. height: 40px;
  71. background-color: #409eff;
  72. color: #ffffff;
  73. border: none;
  74. border-radius: 4px;
  75. font-size: 16px;
  76. cursor: pointer;
  77. transition: background-color 0.3s;
  78. }
  79. /* 按钮hover样式 */
  80. .login-btn:hover {
  81. background-color: #3399ff;
  82. }
  83. /* 密码输入框特殊样式(可选) */
  84. #password {
  85. letter-spacing: 2px;
  86. }
  87. </style>
  88. </head>
  89. <body>
  90. <!--<h1>这是登录界面</h1>-->
  91. <div class="login-container">
  92. <h2 class="login-title">用户登录</h2>
  93. <form action="#" method="post">
  94. <div class="form-item">
  95. <label for="username">账号</label>
  96. <input type="text" id="username" name="username">
  97. </div>
  98. <div class="form-item">
  99. <label for="password">密码</label>
  100. <input type="password" id="password" name="password">
  101. </div>
  102. <input type="button" class="login-btn" value="登录" onclick="login()">
  103. </form>
  104. </div>
  105. </body>
  106. <script>
  107. // 点击登录按钮的时候去发送异步请求
  108. function login() {
  109. // 获取输入框当中账号和密码
  110. var username = document.getElementById("username").value
  111. var password = document.getElementById("password").value
  112. console.log(username,password)
  113. // $: jquery 对象 $.post jquery post 函数
  114. // post 函数第一参数请求路径, 第二个参数: 请求参数 , 第三个参数: 回调函数
  115. $.post("/login",{"username": username,"password": password},function (result){
  116. // 回调函数当中result 就是后端给前端返回数据
  117. if(result.success){
  118. alert("登录成功")
  119. }else{
  120. alert(result.msg)
  121. }
  122. })
  123. }
  124. </script>
  125. </html>