register.html 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. <title>用户注册</title>
  7. <script src="js/jquery-2.1.4.min.js"></script>
  8. <style>
  9. /* 全局样式重置 */
  10. * {
  11. margin: 0;
  12. padding: 0;
  13. box-sizing: border-box;
  14. font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
  15. }
  16. /* 页面背景与居中布局 */
  17. body {
  18. background-color: #f8f9fa;
  19. min-height: 100vh;
  20. display: flex;
  21. justify-content: center;
  22. align-items: center;
  23. padding: 20px;
  24. }
  25. /* 注册卡片容器 */
  26. .register-card {
  27. background: #ffffff;
  28. border-radius: 10px;
  29. box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  30. width: 100%;
  31. max-width: 400px;
  32. padding: 40px 30px;
  33. }
  34. /* 标题样式 */
  35. .register-title {
  36. text-align: center;
  37. color: #333;
  38. font-size: 24px;
  39. margin-bottom: 30px;
  40. font-weight: 600;
  41. }
  42. /* 表单项样式 */
  43. .form-item {
  44. margin-bottom: 20px;
  45. }
  46. /* 标签样式 */
  47. .form-item label {
  48. display: block;
  49. margin-bottom: 8px;
  50. color: #555;
  51. font-size: 14px;
  52. }
  53. /* 输入框样式 */
  54. .form-item input {
  55. width: 100%;
  56. height: 45px;
  57. padding: 0 15px;
  58. border: 1px solid #e0e0e0;
  59. border-radius: 6px;
  60. font-size: 15px;
  61. outline: none;
  62. transition: all 0.3s ease;
  63. }
  64. /* 输入框聚焦效果 */
  65. .form-item input:focus {
  66. border-color: #409eff;
  67. box-shadow: 0 0 0 3px rgba(64, 158, 255, 0.1);
  68. }
  69. /* 输入框占位符样式 */
  70. .form-item input::placeholder {
  71. color: #999;
  72. font-size: 14px;
  73. }
  74. /* 注册按钮样式 */
  75. .register-btn {
  76. width: 100%;
  77. height: 48px;
  78. background-color: #409eff;
  79. color: #ffffff;
  80. border: none;
  81. border-radius: 6px;
  82. font-size: 16px;
  83. font-weight: 500;
  84. cursor: pointer;
  85. transition: background-color 0.3s ease;
  86. margin-top: 10px;
  87. }
  88. /* 按钮hover效果 */
  89. .register-btn:hover {
  90. background-color: #3399ff;
  91. }
  92. /* 按钮禁用状态(可选) */
  93. .register-btn:disabled {
  94. background-color: #a0cfff;
  95. cursor: not-allowed;
  96. }
  97. </style>
  98. </head>
  99. <body>
  100. <div class="register-card">
  101. <h1 class="register-title">用户注册</h1>
  102. <form action="">
  103. <div class="form-item">
  104. <label for="username">账号</label>
  105. <input type="text" placeholder="注册用户名" name="username" id="username">
  106. </div>
  107. <div class="form-item">
  108. <label for="password">密码</label>
  109. <input type="password" placeholder="注册密码" name="password" id="password">
  110. </div>
  111. <input type="button" onclick="register()" value="注册" class="register-btn">
  112. </form>
  113. </div>
  114. <script>
  115. function register(){
  116. var username = $("input[name='username']").val().trim();
  117. var password = $("input[name='password']").val().trim();
  118. // 简单的非空验证(新增)
  119. if(!username) {
  120. alert("请输入用户名!");
  121. return;
  122. }
  123. if(!password) {
  124. alert("请输入密码!");
  125. return;
  126. }
  127. $.post("/register",{username:username,password:password},function (result) {
  128. if(result.success){
  129. alert("注册成功");
  130. }else{
  131. alert(result.msg || "注册失败,请重试");
  132. }
  133. }).fail(function() {
  134. // 新增网络异常提示
  135. alert("网络异常,注册请求发送失败!");
  136. });
  137. }
  138. </script>
  139. </body>
  140. </html>