<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>
<body>
<form action="跳转到的页面.html" onSubmit="return onSubmint()">
账号:<input type="text" id="username" onFocus="nameShow()" onBlur="nameCheck()" onKeyUp="nameCheck()">
<span id="namespan"></span>
<br>
密码<input type="password" id="password" onFocus="passwordShow()" onBlur="passwordCheck()" onKeyUp="passwordCheck()">
<span id="passwordid"></span>
<br>
密码确认<input type="password" id="repassword" onFocus="repasswordShow()" onBlur="repasswordCheck()" onKeyUp="repasswordCheck()">
<span id="repasswordid"></span>
<br>
<input type="submit" value="提交">
</form>
<script type="text/javascript">
//账号
function nameShow(){
var a = document.getElementById("namespan");
a.innerHTML = "<font color='red' size='2'>用户名不能小于6位</font>";
}
function nameCheck(){
var a = document.getElementById("namespan");
var b = document.getElementById("username").value;
if(b.length<6){
a.innerHTML = "<font color='red' size='2'>用户名长度不对</font>";
return false;
}else{
a.innerHTML = "<font color='blue' size='2'>输入正确</font>";
return true;
}
}
//密码
function passwordShow(){
var a = document.getElementById("passwordid");
a.innerHTML = "<font color='red' size='2'> 密码长度为6</font>";
}
function passwordCheck(){
var a = document.getElementById("password");
var b = document.getElementById("passwordid");
if(a.value == null|| a.value==""){
b.innerHTML = "<font color='red' size='2'> 密码不为空</font>";
return false;
}else if(a.value.length<6){
b.innerHTML = "<font color='red' size='2'> 密码长度错误</font>";
return false;
}else{
b.innerHTML = "<font color='blue' size='2'> 密码可以使用</font>";
return true;
}
}
//再次输出密码
function repasswordShow(){
var a = document.getElementById("repasswordid");
a.innerHTML = "<font color='red' size='2'>两次密码必须一致</font>"
}
function repasswordCheck(){
var a = document.getElementById("repasswordid");
var b = document.getElementById("repassword");
var c = document.getElementById("password");
if(b.value == null|| b.value==""){
a.innerHTML = "<font color='red' size='2'> 密码不为空</font>";
return false;
}else if(b.value.length<6){
a.innerHTML = "<font color='red' size='2'> 密码长度错误</font>";
return false;
}else if(b.value != c.value){
a.innerHTML = "<font color='red' size='2'>两次密码不一致</font>";
return false;
}else{
a.innerHTML = "<font color='blue' size='2'>两次密码一致</font>";
return true;
}
}
//确认格式是否都正确
function onSubmint(){
var a = nameCheck() && passwordCheck() && repasswordCheck();
return a;
}
</script>
</body>
</html>
8.5总结
最新推荐文章于 2023-02-17 08:40:33 发布