请老师帮忙检查一下代码
1 | <!DOCTYPE html><br><html><br><br><head><br> <meta charset= "utf-8" ><br> <title>表单验证</title><br><br></head><br><br><body><br> <div class= "box" ><br> <p><b>*</b>用 户 名:<br> <input type= "text" placeholder= "用户名设置成功后不可修改" id= "nameinp" ><br> <span class= "asxd" id= "asxd" >6-30位字母、数字或_,字母开头</span><br> </p><br> </div><br> <div class= "box enter" ><br> <p><b>*</b>登入密码:<br> <input type= "password" placeholder= '6-20位字母或数字' id= "passinp" ><br> <span id= "redbox" class= "box2" ></span><br> <span id= "yellowbox" class= "box2" ></span><br> <span id= "greenbox" class= "box2" ></span><br><br> <span class= 'tishi' id= "tishi" >6-20位字母或数字</span><br> </p><br><br> </div><br> <div class= "box" ><br> <p><b>*</b>确认密码:<br> <input type= "password" placeholder= '再次输入您的登入密码' id= "yeinp" ><br> <span id= "tishi1" ></span><br> </p><br> </div><br> <div class= "box1" ><br> <button id= "button" >注册</button><br> </div><br><br></body><br><br></html><br> |
1 | <style><br> .box {<br> height : 50px ;<br> }<br><br> .box input {<br> width : 220px ;<br> height : 30px ;<br> border-radius: 5px ;<br> border : 1px solid #ccc ;<br> }<br><br> .box b {<br> color : red ;<br> }<br><br> .box 1 {<br> margin-top : 60px ;<br> margin-left : 160px ;<br> }<br><br> .box 1 button {<br> width : 230px ;<br> height : 40px ;<br> background-color : orange;<br> color : white ;<br> text-align : center ;<br> line-height : 40px ;<br> font-size : 18px ;<br> border : none ;<br> border-radius: 5px ;<br> }<br><br> .box .asxd {<br> color : rgba( 255 , 166 , 0 , 0.795 );<br> margin-left : 15px ;<br> }<br><br> .box .tishi {<br> font-size : 12px ;<br> color : red ;<br> margin-left : 100px ;<br> display : none ;<br> }<br><br> .enter {<br> width : 600px ;<br> position : relative ;<br> }<br><br> .enter .box 2 {<br> display : inline- block ;<br> width : 50px ;<br> height : 7px ;<br> background-color : #ccc ;<br> margin-left : 10px ;<br> }<br> </style><br> |
1 | <script><br> var nameinp = document.getElementById( 'nameinp' );<br> var asxd = document.getElementById( 'asxd' );<br> var passinp = document.getElementById( 'passinp' )<br> var yeinp = document.getElementById( 'yeinp' )<br> var tishi = document.getElementById( 'tishi' )<br> var redbox = document.getElementById( 'redbox' )<br> var yellowbox = document.getElementById( 'yellowbox' )<br> var greenbox = document.getElementById( 'greenbox' )<br> var tishi1 = document.getElementById( 'tishi1' )<br> var button= document.getElementById( 'button' )<br> // 用户名离开事件<br> nameinp.onblur = function () {<br> var xinxi = nameinp.value;<br> if (/^[a-zA-Z]\w{5,29}$/.test(xinxi)) {<br> asxd.innerText = '用户名输入正确'<br> asxd.style.color = 'green';<br> } else {<br> asxd.innerText = '6-30位字母、数字或_,字母开头'<br> asxd.style.color = 'red';<br> }<br> }<br> // 登入密码事件<br> passinp.onblur = function () {<br> yellowbox.style.backgroundColor = '#ccc';<br> redbox.style.backgroundColor = '#ccc';<br> greenbox.style.backgroundColor = '#ccc';<br> tishi.style.display = 'none';<br> var xinxi = passinp.value;<br> if (/^[a-zA-Z0-9]{6,20}$/.test(xinxi)) {<br> if (/^[0-9]+$|^[a-z]+$|^[A-Z]+$/.test(xinxi)) {<br> redbox.style.backgroundColor = 'red';<br> } else if (/^[a-z0-9]+$|^[A-Z0-9]+$|^[a-zA-Z]+$/.test(xinxi)) {<br> yellowbox.style.backgroundColor = 'yellow';<br> redbox.style.backgroundColor = 'red';<br> } else if (/^[a-z0-9A-Z]+$/.test(xinxi)) {<br> yellowbox.style.backgroundColor = 'yellow';<br> redbox.style.backgroundColor = 'red';<br> greenbox.style.backgroundColor = 'green';<br> }<br><br> } else {<br> tishi.style.display = 'inline';<br> }<br><br> }<br> // 密码确认框<br> yeinp.onblur = function () {<br> var xinxi = yeinp.value;<br> if (xinxi) {<br> if (passinp.value == xinxi) {<br> tishi1.innerText = '两次输入一致';<br> tishi1.style.color = 'green';<br> } else {<br> tishi1.innerText = '两次密码输入不一致,请重新输入';<br> tishi1.style.color = 'red';<br> }<br> } else {<br> tishi1.innerText = '输入框不能为空';<br> tishi1.style.color = 'red';<br> }<br> }<br> button.onclick=function(){<br> if(/^[a-zA-Z]\w{5,29}$/.test(nameinp.value)&&passinp.value == yeinp.value){<br> alert('信息填写正确');<br> }else{<br> alert('请填写信息正确');<br> }<br> }<br> </script><br> |
16
收起
正在回答 回答被采纳积分+1
2回答
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧