61,128
社区成员




<script>
function check(){
var name=document.getElementById("name").value;
var pass=document.getElementById("pass").value;
if(name=="1" && pass=="1")
{
alert("登入成功");
window.document.f.action="https://www.baidu.com/";
window.document.f.submit();
}else{
alert("用户名或密码错误");
}
}
</script>
<form name="f" action="">
用户名:<INPUT TYPE="text" NAME="" id="name"><br>
密码:<INPUT TYPE="password" NAME="" id="pass"><br>
<INPUT TYPE="button" value="登入" onclick="check()"><INPUT TYPE="reset" value="重置">
</form>
function check() {
var name = document.getElementById("name").value;
var pass = document.getElementById("pass").value;
//你的多用户
var data = [{ name: "a", psd: 1 }, { name: "b", psd: 2 }, { name: "c", psd: 3 }, { name: "d", psd: 4 }];
for (var o in data) {
if (name == data[o].name) {
if (pass == data[o].psd) {
alert("登入成功");
window.document.f.action = "https://www.baidu.com/";
window.document.f.submit();
} else {
alert("密码错误");
}
break;
}
else {
if (o == (data.length - 1)) {
alert("用户名不存在");
break;
}
else {
continue;
}
}
}
}
2.如果数据源是来自于数据库或者表,使用ajax
//这里为用ajax获取用户信息并进行验证,如果账户密码不匹配则登录失败
$.ajax({
url: systemURL,// 获取自己系统后台用户信息接口
data: { "username": name, "password": pass },
type: "GET",
dataType: "json",
success: function (data) {
if (data) {
if (data.code == "1") { //判断返回值,这里根据的业务内容可做调整
showMsg("正在登录中...");
console.log(data);
window.location.href = url;//指向登录的页面地址
} else {
showMsg(data.message);//显示登录失败的原因
return false;
}
}
},
error: function (data) {
showMsg(data.message);
}
});