时间:2021-07-01 10:21:17 帮助过:51人阅读
<!DOCTYPE html>
<html>
<head>
<title>testTablel.html</title>
<!-- 用户名,不能为空
密码6为数字
密码确认,两次输入密码必须相同
身份证号码必须是15位,或者是18位,最末尾也可以是X -->
<style>
#d1 {
width: 400px;
height: 250px;
background-color: #FFE4B5;
margin: 40px auto;
}
#d1_head {
color: white;
font-size: 20px;
font-family: "Arial";
height: 24px;
background-color: bule;
}
#d1_content {
padding-left: 30px;
padding-top: 30px;
}
.s1 {
color: red;
font-style: italic;
}
.s2 {
border: 2px dotted blue;
}
</style>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script>
function check_username(){
var txtObj=document.getElementById("username");
txtObj.className='';
var msgObj=docuemnt.getElementById("username_msg");
msgObj.innerHTML='';
if(txtObj.value.length==0){
msgObj.innerHTML='用户名不能为空';
//给节点的class属性赋值
txtObj.className='s2';
return false;
}
return true;
}
function check_pwd(){
var pwdObj=document.getElementById("pwd");
pwdObj.classNames='';
var msgObj=document.getElementById("pwd_msg");
msgObj.innerHTML='';
var reg=/^\d{6}$/;
//javascript中一个test方法,返回boolean
if(!reg.test(pwdObj.value)){
msgObj.innerHTML='密码是6位数';
pwdObj.className='s2';
return false;
}
return true;
}
function check_pwd1(){
var pwdObj=document.getElementById("pwd");
// pwdObj.classNames='';
// var msgObj=document.getElementById("pwd_msg");
// msgObj.innerHTML='';
var pwdObj1=document.getElementById("pwd1");
//pwdObj1.classNames='';
var msgObj1=document.getElementById("pwd_msg1");
msgObj1.innerHTML='';
if(pwdObj.value!=pwdObj1.value){
msgObj1.innerHTML='密码不一致,请重新输入';
return false;
}
return true;
}
function check_form(){
var flag=check_username()&&check_pwd()&&check_pwd1;
return flag;
}
</script>
</head>
<body>
<div id="d1">
<div id="d1_head">注册</div>
<div id="d1_content">
<form onsubmit="return check_form();">
<table>
<tr>
<td>用户名</td>
<td><input id="username" name="username"
onblur="check_username();" /> <span class="s1" id="username_msg"></span>
</td>
</tr>
<tr>
<td>密码</td>
<td><input type="password" id="pwd" name="pwd"
onblur="check_pwd();" /> <span class="s1" id="pwd_msg"></span></td>
</tr>
<tr>
<td>确认密码</td>
<td><input type="password" id="pwd1" name="pwd1"
onblur="check_pwd1();" /> <span class="s1" id="pwd_msg1"></span>
<tr>
<td colspan="2">
<input type="submit" value="确认" /> <input type="reset"
value="重置" />
</td>
</tr></table>
</form>
</div>
</div>
</body>
</html>