烦请各位帮忙看下下面的一段代码,javascript的问题。

 <style>

        div{

            width:600px;

            margin:200px auto;

        }

        #tishi{

            display:inline-block;

            background:url(./images/mess.png) no-repeat left center;

            padding-left:20px;

            font-size:12px;

            color:#999;

        }

        #right{

            background-image:url(./images/right.png);

            color:green;

        }

        #wrong{

            background-image:url(./images/wrong.png);

            color:red;

        }

    </style>

</head>

<body>

    <div>

        <input type="password">

        <p id="tishi">请输入6-16位密码</p>

    </div>

    <script>

        var input=document.querySelector('input');

        var p=document.querySelector('#tishi');

        input.onblur=function(){

            if(input.value.length<6||input.value.length>16){

                p.className='tishi wrong';

                p.innerHTML='输入错误'

            }

            else{

                p.className='tishi right';

                p.innerHTML='正确';

            }

        }

    </script>

</body>

</html>

看了很多遍就是没找到问题在哪,

把p标签里的选择器改为类选择器就好了,

但是想知道为啥我用id选择器就出错呢?

请各位帮忙看看。谢谢


Explorernb
浏览 573回答 0
0回答

慕婉清7572070

风格低功耗防静电
打开App,查看更多内容
随时随地看视频慕课网APP