Home > Web Front-end > HTML Tutorial > Line: 13 Error: 'null' is empty or not an object

Line: 13 Error: 'null' is empty or not an object

PHP中文网
Release: 2016-06-24 12:08:52
Original
1676 people have browsed it

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>
Copy after login

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


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template