<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
账号:<input id="username" name="username" /><br />
密码:<input id="password" name="pasword" /><br />
<button onclick="register()">注册</button>
<script type="text/javascript">
//创建用户和密码库
var usernames = ["lili","xiaoli"];
var passwords = ["12345","23456"];
//当用户点击注册时触发事件
function register(){
//获取用户输入内容,账户和密码
var username = document.getElementById("username").value;
var pasword = document.getElementById("password").value;
//判断用户输入内容是否与用户库一致,0是不存在,1是存在
var yan = 0;
for(var i = 0; i < usernames.length; i++){
if(usernames[i] == username){
//当yan == 1 说明重名
yan = 1;
break
}
}
//判断账户首字母大小写
if(username[0]<"A" || username[0]>"Z"){
alert("首字母错误");
}else{
alert("首字母正确");
//判断账户长度,密码长度,是否重名
if(username.length>=6 && username.length<=12 &&
pasword.length>=6 && pasword.length<=12 &&
yan == 0){
alert("注册成功");
window.location = "登录改.html?username="+username+"&pasword="+pasword
}else{
alert("注册失败");
}
}
}
</script>
</body>
</html>
03-27
2195
10-09
9210
06-10
661