Home  >  Article  >  Web Front-end  >  The problem of conflict between js function name and form element with the same name_javascript skills

The problem of conflict between js function name and form element with the same name_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:56:391160browse

Today when exporting Excel, I used the input hidden of the Form form to distinguish export and search. At the beginning, the function name of the onClick event in js is the same as the id in hidden. As a result, an error is reported: The object in the line where the function is called does not support this attribute.

After searching for a long time, I couldn’t find the reason. At first, I thought it was a wrong letter, only to find that the js function was not executed at all. Later, I couldn't directly call other functions, and found that it worked. I thought it was because of the function name, so I changed the function name before it worked. Then I changed the id in the input to be the same as the function name, and another error occurred. Before verifying it with the following example, I always thought it was a bug in ThinkPHP template parsing. Because of the following example, it is confirmed that the function name in js cannot be the same as the id in the element.

For example:

Copy the code The code is as follows:




ceshi
<script><br>function a()<br>{<br> document.getElementById('a').value="test";<br> alert(document.getElementById('a').value) ;<br> return false;<br>}<br></script>









Webpage error details

User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; CIBA; .NET CLR 2.0.50727)
Timestamp: Thu, 27 Jan 2011 13:30:09 UTC

Message: Object does not support this property or method
Lines: 17
Characters: 1
Code: 0
URI: file:///C:/Documents and Settings/Administrator/Desktop /test.html

Statement:
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