目录
JavaScript实战三——员工注册页面
功能如下:
合理布局;
样式自行发挥,重置按钮重置输入框;
实现注册功能,页面通过正确方式提交至信息页;
信息页面包含一个表格;
信息页面能够读取注册页面提交的数据,正确回显数据。
注册页面
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>information</title>
<style>
*{
margin: 0;
}
.mainbox{
background-color:white;
margin: 8px;
border:solid 2px;
min-height: 800px;
text-align: center;
}
.list{
margin:0px auto;
height: 600px;
}
.header{
background-color:orange;
text-align:left;
height: 20px;
line-height: 20px;
padding: 5px;
}
table{
margin: 100px auto;
}
tr{
height: 50px;
padding: 5px;
}
.footer{
height: 100px;
margin:20px auto;
}
.btn{
height: 60px;
margin:20px auto;
}
.register{
width :150px;
background-color: orange;
}
.reset{
width: 150px;
background-color: orange;
}
input{
padding-left: 4px;
}
.tleft{
text-align: right;
font-weight: bolder;
font-size: 15px;
}
.tright{
text-align: left;
}
</style>
<script type="text/javascript">
window.onload=function(){
var button1=document.getElementById("reset");
var button2=document.getElementById("register")
button1.onclick=function(){
document.getElementById("text0").value="";
document.getElementById("text1").value="";
document.getElementById("text2").value="";
document.getElementById("text3").value="";
document.getElementById("text4").value="";
document.getElementById("text5").value="";
document.getElementById("text6").value="";
document.getElementById("text7").value="";
}
register.onclick=function(){
var uname = document.getElementById("text0");
var upwd1 = document.getElementById("text1");
var upwd2 = document.getElementById("text2");
var uidnum = document.getElementById("text4");
var utel = document.getElementById("text5");
var check = document.getElementById("checking");
if (uname.value == "") {
alert("错误:用户名不能为空!");
uname.focus();
return false;
}
reg0 = /^[0-9a-zA-Z|_]{6,20}$/;
if (!reg0.test(uname.value)) {
alert("错误:用户名必须只包含字母、数字,下划线!且需要6-20位");
uname.focus();
return false;
}
if (upwd1.value == "" || upwd1.value != upwd2.value) {
alert("错误:请检查并确认您输入的密码是否一致!");
upwd1.focus();
return false;
}
if (check.checked == false) {
alert("错误:请检查并确认您是否勾选!");
check.focus();
return false;
}
else {
window.sessionStorage.setItem("userName", uname.value);
window.sessionStorage.setItem("uName", document.getElementById("text3").value);
var obj=document.getElementsByName("gender");
for(var i=0; i<obj.length; i ++){
if(obj[i].checked){
window.sessionStorage.setItem("UserSex", obj[i].value);
}
}
window.sessionStorage.setItem("iDnum", uidnum.value);
window.sessionStorage.setItem("telNum", utel.value);
window.sessionStorage.setItem("eMail", document.getElementById("text6").value);
window.sessionStorage.setItem("creditNum", document.getElementById("text7").value);
window.sessionStorage.setItem("openBank", document.getElementById("text8").value);
}
}
}
</script>
</head>
<body>
<div class="mainbox">
<div class="header">
账户信息
</div>
<form method="get" action="./information.html" autocomplete="on" >
<div class="list">
<table>
<tr>
<td class="tleft"><label>* 用户名:</label></td>
<td class="tright"><input type="text" placeholder="用户名2-4个,设置成功后不可修改" id="text0"><span id="unameSpan"></span></td>
</tr>
<tr>
<td class="tleft"><label>* 登录密码:</label></td>
<td class="tright"><input type="password" placeholder="6-20位字母,数字或字符" id="text1"></td>
</tr>
<tr>
<td class="tleft"><label>* 确认密码:</label></td>
<td class="tright"><input type="password" placeholder="再次输入您的登录密码" id="text2"></td>
</tr>
<tr>
<td class="tleft"><label>* 姓 名:</label></td>
<td class="tright"><input type="text" placeholder="请输入姓名" id="text3"></td>
</tr>
<tr>
<td class="tleft"><label>* 性 别:</label></td>
<td class="tright" style="text-align: left;">
<input type="radio" name="gender" value="男" checked="checked">男
<input type="radio" name="gender" value="女">女
</td>
</tr>
<tr>
<td class="tleft"><label>* 证件号码:</label></td>
<td class="tright"><input type="text" placeholder="请输入您的身份证件号" id="text4"></td>
</tr>
<tr>
<td class="tleft"><label>* 手机号码:</label></td>
<td class="tright"><input type="text" placeholder="请输入您的手机号码" id="text5"></td>
</tr>
<tr>
<td class="tleft"><label>邮 箱:</label></td>
<td class="tright"><input type="text" placeholder="请正确填写邮箱地址" id="text6"></td>
</tr>
<tr>
<td class="tleft"><label>* 银行卡号:</label></td>
<td class="tright"><input type="text" placeholder="请输入银行卡号" id="text7"></td>
</tr>
<tr>
<td class="tleft"><label>* 开户行:</label></td>
<td class="tright">
<input type="text" list="bank" placeholder="中国银行" id="text8">
<datalist class="bank" id="bank">
<option>中国银行</option>
<option>中国建设银行</option>
<option>中国交通银行</option>
<option>中国工商银行</option>
</datalist>
</td>
</tr>
<tr>
<td class="tleft"></td>
<td class="tright">
<input type="checkbox" name="clause" value="agree" class="clause" id="checking"> 我已阅读并同意服务条款
</td>
</tr>
<tr>
<td class="tleft"><input type="submit" class="register" id="register" value="注册" ></td>
<td class="tright"><input type="button" class="reset" id="reset" value="重置"></td>
</tr>
</table>
</div>
</form>
</div>
</body>
</html>
信息页面
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>information</title>
<style>
*{
margin: 0px;
}
table tr td{
border:solid 2px black;
}
table{
margin: 100px auto;
width: 1000px;
min-height: 25px;
line-height: 50px;
text-align: center;
border-color:#b6ff00;
border-collapse: collapse;
}
tr td{
height: 50px;
border-collapse: collapse;
}
.tleft{
text-align: center;
font-weight: bolder;
font-size: 15px;
}
.tright{
width: 400px;
text-align: center;
}
.inner {
text-align: center;
height: 30px;
width: 200px;
margin: 10px;
}
</style>
<script type="text/javascript">
function show(){
document.getElementById("user").innerHTML = window.sessionStorage.getItem("userName");
document.getElementById("anam").innerHTML = window.sessionStorage.getItem("uName");
document.getElementById("usex").innerHTML = window.sessionStorage.getItem("UserSex");
document.getElementById("uidc").innerHTML = window.sessionStorage.getItem("iDnum");
document.getElementById("utel").innerHTML = window.sessionStorage.getItem("telNum");
document.getElementById("uema").innerHTML = window.sessionStorage.getItem("eMail");
document.getElementById("ucar").innerHTML = window.sessionStorage.getItem("creditNum");
document.getElementById("uban").innerHTML = window.sessionStorage.getItem("openBank");
}
</script>
</head>
<body onload="show()">
<table id="table">
<caption style="font-size: 15px;font-weight: bolder;">用户信息表</caption>
<tr>
<td class="tleft">用户名</td>
<td class="tleft">姓名</td>
<td class="tleft">性别</td>
<td class="tleft">证件号码</td>
<td class="tleft">手机号码</td>
<td class="tleft">邮箱</td>
<td class="tleft">银行卡号</td>
<td class="tleft">开户行</td>
</tr>
<tr>
<tr>
<td class="tright"><div class="inner" id="user"></div></td>
<td class="tright"><div class="inner" id="anam"></div></td>
<td class="tright"><div class="inner" id="usex"></div></td>
<td class="tright"><div class="inner" id="uidc"></div></td>
<td class="tright"><div class="inner" id="utel"></div></td>
<td class="tright"><div class="inner" id="uema"></div></td>
<td class="tright"><div class="inner" id="ucar"></div></td>
<td class="tright"><div class="inner" id="uban"></div></td>
</tr>
</tr>
</table>
</body>
</html>