81,122
社区成员




<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
昵称:<input type="text" id="username" onblur="named()">
<div id="b4"></div>
账号:<input type="text" id="pid" onblur="pid()">
<div id="b1"></div>
密码:<input type="password" id="passwd1" onblur="demo()">
<div id="b2"></div>
密码:<input type="password" id="passwd2" onblur="mima()">
<div id="b3"></div>
<button id="btn">提交</button>
<script>
function $(id) {
return document.getElementById(id)
}
let name = $('username')
let nick = $('pid')
let pwd1 = $('passwd1')
let pwd2 = $('passwd2')
let b1 = $('b1')
let b2 = $('b2')
let b3 = $('b3')
let b4 = $('b4')
let btn = $('btn')
btn.disabled = true // 初始设置不能点击
//验证用户名
function named() {
if (name.value.length < 11) {
b4.innerHTML = "<font size='2' color='red'>昵称长度不够";
} else {
b4.innerHTML = "<font size='4' color='lime'>√";
}
}
function pid() {
if (nick.value.length < 11) {
b1.innerHTML = "<font size='2' color='red'>账号长度不够";
} else {
b1.innerHTML = "<font size='4' color='lime'>√";
}
}
//验证密码
function demo() {
if (pwd1.value.length < 6) {
b2.innerHTML = "<font size='2' color='red'>密码长度不够";
} else {
b2.innerHTML = "<font size='4' color='lime'>√";
}
}
//验证确认密码
function mima() {
if(pwd2.value!=="") {
if (pwd1.value == pwd2.value) {
b3.innerHTML = "<font size='4' color='lime'>√";
btn.disabled = false;
} else {
b3.innerHTML = "<font size='2' color='red'>两次密码不一致";
btn.disabled = true;
}
} else {
b3.innerHTML = "<font size='2' color='red'>再次密码长度不够";
btn.disabled = true;
}
}
</script>
</script>
</body>
完善一下密码验证代码,你账户名用id作为方法名,这个是关键字,应该是有问题的