The code is as follows
<script language="JavaScript"> function check(){ var tx=document.form1.username.value; var d=document.getElementById("p1"); if (!tx.match("^[a-zA-Z0-9_]{10,13}$")) { d.outerText="你输入的用户名非法!"; } else{ d.style.visibility ="hidden"; } } </script> </head> <body> <form name="form1"> 用户名:<input type="text" name="username" onmouseleave="return check()"/> <p id="p1">请输入5到10为用户名!</p> </form> </body>
Prompt: Line: 13 Error: 'null' is empty or not an object, how to solve it?
Solution:
Change d.outerText="you enter The username you entered is illegal!";
Changed to
d.innerHTML="The username you entered is illegal!";
Because after your outerText, p no longer exists.
innerText
innerHTML changes the content inside
outer changes the outside. Even the label has been replaced and it won’t work next time. So it is null