Home > Web Front-end > JS Tutorial > Solution to console error object is not a function_Basic knowledge

Solution to console error object is not a function_Basic knowledge

WBOY
Release: 2016-05-16 16:38:49
Original
1803 people have browsed it

A BUG was reported today, saying that a function on a page cannot be used. Open the console and find an error: object is not a function.

It feels very strange. This function has not been touched recently, so why does it suddenly cause problems? All major browsers were tested when it went online.

Although it is strange, it still solves the problem. Looking at the code, I found that the name attribute of a radio object has the same name as a function name. The code is as follows:

<body> 
<input type="radio" name="test" onclick="test();"/> 
<br/> 
<form action=""> 
<input type="radio" name="test" onclick="test();"/> 
</form> 
</body> 
<script type="text/javascript"> 
function test(){ 
alert("11"); 
}
</script>
Copy after login

Modified the function name and solved the problem. But the root cause was not found, because the function name was like this before and could be used normally. Modify code
onclick="alert(test);"

I found that "object HTMLInputElement" popped up, and the browser parsed the test into a dom object.

After the script test function alert(test); is still a function.

Looking at the svn version, I found that I added a form to wrap up the radio when I was doing another function. This causes browser parsing errors.

Summary: The code that has not been changed may not be a problem. Maybe the changes have caused other problems. Some browser compatibility issues are caused by code irregularities. You must write code in a standardized manner in the future!

If any expert knows why browser parsing problem occurs after adding form, can you tell me. Thank you so much!

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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template