jquery写登录页面

//密码可见切换

$("i.pwd-icon").on("click", function() {

 

if($(this).hasClass("icon-eye_protection")) {

// 令其可见

 

$("#txtPwd").attr("type", "text");

$(this).removeClass("icon-eye_protection")

.addClass("icon-shut_down");

$(this).attr("title", "不显示密码内容");

 

}else if($(this).hasClass("icon-shut_down")) {

//不可见

 

$("#txtPwd").attr("type", "text");

$(this).removeClass("icon-shut_down")

.addClass("icon-eye_protection");

$(this).attr("title", "显示密码内容");

 

}

});

// 回车事件

$("#txtUser").keydown(function (event) {

if (event.keyCode == 13) {

$("#txtPwd").focus();

}

});

 

$(

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个使用jQuery实现登录页面的示例代码: HTML代码: ``` <!DOCTYPE html> <html> <head> <title>登录页面</title> <meta charset="utf-8"> <script src="https://cdn.bootcss.com/jquery/3.5.1/jquery.min.js"></script> <script src="login.js"></script> </head> <body> <h2>用户登录</h2> <form id="login-form"> <label for="username">用户名:</label> <input type="text" id="username" name="username"><br><br> <label for="password">密码:</label> <input type="password" id="password" name="password"><br><br> <input type="submit" value="登录"> </form> <div id="error-message"></div> </body> </html> ``` JavaScript代码(login.js): ``` $(document).ready(function() { $("#login-form").submit(function(event) { // 阻止表单的默认提交行为 event.preventDefault(); // 获取表单数据 var formData = { 'username': $('input[name=username]').val(), 'password': $('input[name=password]').val() }; // 发送POST请求到后端验证登录 $.ajax({ type: 'POST', url: 'login.php', data: formData, dataType: 'json', encode: true }) .done(function(data) { // 登录成功跳转到用户首页 if (data.success) { window.location.href = 'user_homepage.html'; } // 登录失败提示错误信息 else { $("#error-message").html(data.message); } }) .fail(function(xhr, status, error) { console.log(xhr.responseText); console.log(status); console.log(error); }); }); }); ``` 注意:以上代码中的登录验证需要在后端实现,这里只是前端示例代码。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值