请问这样是出什么问题了?

请问这样是出什么问题了?

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style type="text/css">
        *{
            margin: 0;
            padding: 0;
        }
        header{
            width: 100%;
            height: 60px;
            background-color: #3092d1;
            color: #fff;
            text-align: center;
            line-height: 60px;
        }
        .content{
            width: 100%;
            height: 600px;
            background-color: #eeeeee;
            padding-top: 60px;
        }
        .content>div{
            width: 800px;
            height: 24px;
            margin-bottom: 30px;
            position: relative;
            left: 50%;
            margin-left: -400px;
        }
        .content>div>label{
            width: 100px;
            margin-right: 60%;
            position: absolute;
            right: 30px;
            line-height: 24px;
        }
        .content>div>input{
            width: 200px;
            position: absolute;
            left: 50%;
            margin-left: -100px;
            line-height: 24px;
        }
        .content>div>select{
            width: 205px;
            height: 28px;
            position: absolute;
            left: 50%;
            margin-left: -100px;
            line-height: 24px;
        }
        .content>div>span{
            width: 350px;
            position: absolute;
            left: 66%;
            line-height: 24px;
            color: #f00;
        }
        .content>input{
            width: 80px;
            height: 40px;
            position: absolute;
            left: 50%;
            margin-left: -40px;
            margin-top: 40px;
            background-color: #2375ba;
            color: #fff;
            border: 0px solid;
            border-radius: 10px;
            cursor: pointer;
        }
    </style>
</head>
<body>
    <header>
        <h2>用户注册</h2>
    </header>
    <div class="content">
        <div>
            <label for="">用户名:</label>
            <input type="text" id="username" value="">
            <span id="usernamespan"></span>
        </div>
        <div>
            <label for="">登录密码:</label>
            <input type="password" id="password" value="">
            <span id="passwordspan"></span>
        </div>
        <div>
            <label for="">确认密码:</label>
            <input type="password" id="confirm" value="">
            <span id="confirmspan"></span>
        </div>
        <div>
            <label for="">姓名:</label>
            <input type="text" id="name" value="">
            <span id="namespan"></span>
        </div>
        <div>
            <label for="">性别:</label>
            <select id="sex">
                <option>男</option>
                <option>女</option>
            </select>
            <span id="sexspan"></span>
        </div>
        <div>
            <label for="">身份证号码:</label>
            <input type="text" id="idnum" value="">
            <span id="idnumspan"></span>
        </div>
        <div>
            <label for="">邮箱:</label>
            <input type="text" id="email" value="">
            <span id="emailspan"></span>
        </div>
        <div>
            <label for="">手机号码:</label>
            <input type="text" id="phonenum" value="">
            <span id="phonenumspan"></span>
        </div>
        <input type="submit" name="" value="提交" id="submit">
    </div>
    <script type="text/javascript">
        // 正则
        var RegExp={
            usernameReg:/^[A-Za-z]\w{5,19}$/,
            passwordReg:/[^\s]{6,18}/,
            nameReg:/[\u4e00-\u9fa5]{2,4}/,
            idnumReg:/\d{17}[\d|x]|\d{15}/,
            emailReg:/\w[-\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\.)+[A-Za-z]{2,14}/,
            phonenumReg:/^(?:150|151|152|153|155|156|157|158|159|130|131|132|133|134|135|136|137|138|139|180|182|185|186|187|188|189)[0-9]{8}$/
        };

        // 定义获取DOM的函数
        function get(ele){
            var ele=document.getElementById(ele);
        }

        // 获取DOM
        get(username);  get(usernamespan);
        get(password);  get(passwordspan);
        get(confirm);   get(confirmspan);
        get(name);      get(namespan);
        get(idnum);     get(idnumspan);
        get(email);     get(emailspan);
        get(phonenum);  get(phonenumspan);
        get(submit);

        // 用户名判定函数
        function usernamejudge(){
            if(RegExp.usernameReg.test(username.value)){
                usernamespan.innerHTML="OK";
            }
            else{
                usernamespan.innerHTML="6-20位字母、数字或“_”,字母开头";
            }
        }

        // 密码判定函数
        function passwordjudge(){
            if(RegExp.passwordReg.test(password.value)){
                passwordspan.innerHTML="OK";
            }
            else{
                passwordspan.innerHTML="6-18位,包括数字字母或符号,中间不能有空格";
            }
        }

        // 确认密码判定函数
        function confirmjudge(){
            if(confirm.value==password.value){
                confirmspan.innerHTML="OK";
            }
            else{
                confirmspan.innerHTML="请设置密码";
            }
        }

        // 姓名判定函数
        function namejudge(){
            if(RegExp.nameReg.test(name.value)){
                namespan.innerHTML="OK";
            }
            else{
                namespan.innerHTML="真实姓名为两位到四位的中文汉字";
            }
        }

        // 身份证号判定函数
        function idnumjudge(){
            if(RegExp.idnumReg.test(idnum.value)){
                idnumspan.innerHTML="OK";
            }
            else{
                idnumspan.innerHTML="请输入15位或者18位的身份证号码";
            }
        }

        // 邮箱判定函数
        function emailjudge(){
            if(RegExp.emailReg.test(email.value)){
                emailspan.innerHTML="OK";
            }
            else{
                emailspan.innerHTML="邮箱格式不正确";
            }
        }

        // 手机号判定函数
        function phonenumjudge(){
            if(RegExp.phonenumReg.test(phonenum.value)){
                phonenumspan.innerHTML="OK";
            }
            else{
                phonenumspan.innerHTML="电话号码不正确";
            }
        }

        // 绑定失焦函数
        username.onblur=usernamejudge;
        password.onblur=passwordjudge;
        confirm.onblur=confirmjudge;
        name.onblur=namejudge;
        idnum.onblur=idnumjudge;
        email.onblur=emailjudge;
        phonenum.onblur=phonenumjudge;

        // 绑定提交按钮点击事件
        submit.onclick=function(){
            usernamejudge();
            passwordjudge();
            confirmjudge();
            namejudge();
            idnumjudge();
            emailjudge();
            phonenumjudge();
        }

    </script>
</body>
</html>

为什么确认密码和姓名部分失焦时不会出现提示?其它的明明可以呀

正在回答

登陆购买课程后可参与讨论,去登陆

1回答

你好,是因为name和confirm是window对象中原有的属性和方法:

http://img1.sycdn.imooc.com//climg/5cdba8300001f9ee03940128.jpg

直接使用会有冲突,并且代码中写的get()方法并没有获取的到元素,是直接使用的id值,因为id值代表页面中的唯一,是可以直接使用的,可以修改为:

http://img1.sycdn.imooc.com//climg/5cdba8b500013ca007330638.jpg

http://img1.sycdn.imooc.com//climg/5cdba8c10001b83007090274.jpg

http://img1.sycdn.imooc.com//climg/5cdba8ce0001f90b08740242.jpg

http://img1.sycdn.imooc.com//climg/5cdba8d80001895005120256.jpg

可以修改测试下,祝学习愉快!

问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
2.组件化网页开发
  • 参与学习           人
  • 提交作业       1121    份
  • 解答问题       14456    个

本阶段在运用JS实现动态网页开发的基础上,带你深入理解企业开发核心思想,完成一个企业级网页的开发,体验前端工程师的成就感。

了解课程
请稍等 ...
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师