ID和函数名称相同时未调用Javascript函数 [英] Javascript function not called when id and function name same
本文介绍了ID和函数名称相同时未调用Javascript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道当 id
和 function
相同时会有什么作用.示例:
I want know the what is the effect of id
and function
when both are same. Example:
<tr> <td><img id='deleteAuthor' onclick='javascript: deleteAuthor(this)' src='images/close.png' /></td></tr>";
function deleteAuthor(element){
alert(element);
}
output:TypeError: deleteAuthor is not a function
[Break On This Error]
<tr> <td><img id='deleteAuthorbt' onclick='javascript: deleteAuthor(this)' src='images/close.png' /></td></tr>";
function deleteAuthor(element){
alert(element);
}
output:Object HTMLImageElement
请问为什么会这样?
推荐答案
U必须为id和function使用不同的名称.两者的名称相同会引起歧义
U have to use different names for id and function. Same names for both will cause ambiguity
这篇关于ID和函数名称相同时未调用Javascript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文