用户登陆界面(jquery)

 1 <!DOCTYPE html>
 2 <html>
 3     <head>
 4         <meta charset="UTF-8">
 5         <title></title>
 6     </head>
 7     <script src="js/jquery-1.8.0.min.js"></script>
 8     <script>
 9         var cnresu = false;
10         $(function(){
11             $("input[name='uname']").blur(function(){//blur从链接上移开焦点(鼠标离开框时)
12                 var unamestr = $(this).val();
13                 var regstr = /^[\u4e00-\u9fa5]{2,4}$/;
14                 if(!regstr.test(unamestr)){
15                     $(this).parent().next("dd").html("必须是2-4个汉字");
16                     cnresu = false;
17                     return;
18                 }
19                 cnresu = true;
20             });
21             $("input[name='uname']").focus(function(){//focus给予链接焦点(鼠标点中框时)
22                 $(this).css("border","solid 1px #dddddd");
23                 //$(this).val("");
24                 $(this).parent().next("dd").html("");
25             });
26         });
27     </script>
28     <style>
29         #home{
30             width: 600px;
31             height: 300px;
32             margin: auto;
33             background-color: #7FFFD4;
34         }
35         #head{
36             padding-top: 20px;
37             height: 100px;
38         }
39         .dl1{
40             clear: both;
41         }
42         .dl1 dt{
43             float: left;
44             text-align: right;
45             width: 150px;
46             height: 30px;
47             line-height: 30px;
48         }
49         .dl1 dd{
50             float: left;
51             height: 30px;
52             line-height: 30px;
53         }
54         #foot{
55             text-align: center;
56         }
57         h1{
58             padding-top: 20px;
59             text-align: center;
60             color: bisque;
61         }
62     </style>
63     <body>
64         <div id="home">
65             <h1>用户登陆</h1>
66             <div id="head">
67             <form action="biaodan.html" name="regform" method="post" >
68                 <dl class="dl1">
69                     <dt>用户名 : </dt>
70                     <dd><input type="text" name="uname"/></dd>
71                     <dd id="erroruname"></dd>
72                 </dl>
73                 <dl class="dl1">
74                     <dt>密码 : </dt>
75                     <dd><input type="password"/></dd>
76                     <dd id="errorpass"></dd>
77                 </dl>
78             </div>
79                 <div id="foot">
80                     <input type="submit" value="提交"/>
81                     <input type="reset" value="重置"/>
82                 </div>
83             </form>
84         </div>
85     </body>
86 </html>

 

 

运行截图

 

转载于:https://www.cnblogs.com/a1045417817/p/7479599.html

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个使用jQuery实现的登录界面的示例代码: ```html <!DOCTYPE html> <html> <head> <title>Login Page</title> <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script> type="text/css"> body { background-color: #f2f2f2; font-family: Arial, sans-serif; } .container { margin: 100px auto; width: 400px; background-color: #fff; padding: 20px; border-radius: 5px; box-shadow: 0px 0px 10px #999; } h2 { text-align: center; margin-bottom: 30px; } input[type="text"], input[type="password"] { width: 100%; padding: 10px; margin-bottom: 20px; border-radius: 5px; border: none; box-shadow: 0px 0px 5px #999; } input[type="submit"] { background-color: #4CAF50; color: #fff; padding: 10px; border: none; border-radius: 5px; cursor: pointer; width: 100%; } input[type="submit"]:hover { background-color: #3e8e41; } .error { color: red; margin-bottom: 10px; } </style> <script type="text/javascript"> $(document).ready(function() { $("#login-form").submit(function(event) { event.preventDefault(); var username = $("#username").val(); var password = $("#password").val(); if (username == "" || password == "") { $(".error").html("Please enter both username and password."); } else { $(".error").html(""); $.ajax({ url: "login.php", type: "POST", data: {username: username, password: password}, success: function(response) { if (response == "success") { window.location.href = "home.php"; } else { $(".error").html("Invalid username or password."); } } }); } }); }); </script> </head> <body> <div class="container"> <h2>Login</h2> <form id="login-form"> <label>Username:</label> <input type="text" id="username" name="username"> <label>Password:</label> <input type="password" id="password" name="password"> <input type="submit" value="Login"> <div class="error"></div> </form> </div> </body> </html> ``` 这个示例代码包含一个登录表单,当用户点击“登录”按钮时,使用jQuery的ajax方法向服务器发送POST请求,将用户名和密码作为数据发送。服务器返回“success”表示登录成功,此时页面跳转到home.php页面;否则,显示错误信息“Invalid username or password.”。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值