<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选择器就出错呢?请各位帮忙看看。谢谢
添加回答
举报
0/150
提交
取消