<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="css/login.css" type="text/css">
<script src="js/jquery-1.11.2.js"></script>
<script src="js/jquery-1.11.1.min.js"></script>
<script src="js/jquery-3.2.0.min.js"></script>
<script>
$().ready(function(){
$("#login input").click(function(){
var Number = $("#div_1 div:nth-child(2) input").val();
var passwd = $("#div_2 div:nth-child(2) input").val();
var errorMsg = "";
if(Number == ""){
errorMsg = "工号不能为空";
}
else if(passwd == ''){
errorMsg = '密码不能为空';
}
if(errorMsg != ""){
$("#error").text(errorMsg);
}
else{
document.location.href = "main.html";
}
});
$("#cancel input").click(function(){
$("#div_1 div:nth-child(2) input").val('');
$("#div_2 div:nth-child(2) input").val('');
})
});
</script>
</head>
<body>
<div id="div_1">
<div class="gonghao">工号</div>
<div><input type="text" name="" id="number" placeholder="请输入工号"></div>
</div>
<div id="div_2">
<div>密码</div>
<div><input type="password" name="" id="passwd" placeholder="请输入密码"></div>
</div>
<div id="div_3">
<div id="login"><input type="button" name="" id="" value="登录"></div>
<div id="cancel"><input type="button" name="" id="" value="取消"></div>
<div id="error"></div>
</div>
</body>
<script>
$("#loginBtn").click(function() {
var userno = $("#userno").val();
var userpwd = $("#userpwd").val();
$.ajax({
url: "http://120.79.153.0:8080/login.aspx",
type: "GET",
data: {
userno: userno,
userpwd: userpwd
},
dataType: "json",
success: function(response) {
if (response == "TRUE") {
alert("登录成功");
// 记录当前用户工号,并跳转至管理员操作主页面main.html
localStorage.setItem("userno", userno);
window.location.href = "main.html";
} else {
alert("登录失败,请重新登录");
}
},
error: function(xhr, status, error) {
alert("登录失败,请检查网络连接或重试");
}
});
});
</script>
</html>
测试的代码
最新推荐文章于 2024-06-20 15:08:10 发布