您当前的位置: 首页 > 

暂无认证

  • 2浏览

    0关注

    92582博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

dom啦16 表单校验 核心在于:一样先做完再另一样把。慢慢纠正把。

发布时间:2020-09-06 22:22:35 ,浏览量:2

<!DOCTYPE html> <html> <head> <title></title> <style type="text/css"> </style> </head> <body> <form action="http://www.it666.com"> <input type="text" name="" id="" placeholder="请输入账号" name="userName"> <input type="password" name="" id="" placeholder="请输入密码" name="userPwd"> <input type="submit" value="注册"> </form> <script type="text/javascript"> /*
    需求:
    1.账号和密码必须大于等于6位
    2.如果账号密码的长度不够就改变input输入框的背景颜色
    3.如果用户输入的账号或者密码不符合需求, 那么就不能提交
    */ let oUserName =document.querySelector("input[type=text]"); let oPassword = document.querySelector("input[type=password]"); let oSubmit =document.querySelector("input[type=submit]"); oSubmit.onclick=function() { // 1.账号和密码必须大于等于6位 if(oUserName.value.length<6) { oUserName.style.background="yellow"; return false; } else { oUserName.style.background="#fff"; } if (oPassword.value.length<6) { oPassword.style.background="red"; return false; } else { oPassword.style.background="#fff"; } } </script> </body> </html> 
关注
打赏
1653961664
查看更多评论
立即登录/注册

微信扫码登录

0.0473s