2
id
과 function
의 효과는 무엇인지 알고 싶습니다. 예 :id와 함수 이름이 같은 경우 자바 스크립트 함수가 호출되지 않음
<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
제발 그렇게 행동하는 이유는 무엇입니까?
요소 ID와 함수가 모두 전역 범위에서 충돌하여 요소 참조가 재정의되어 함수 참조가 무시됩니다. –
자세히 알아보기 http://stackoverflow.com/questions/3434278/ie -chrome-are-dom-tree-elements-global-variables-here 여기 –
[TypeError : prc.cng()의 중복 가능한 내용이 Firefox에서 발견되지 않음 TypeError : Object #에 'cng'메서드가 없습니다. 크롬] (http://stackoverflow.com/questions/16581252/typeerror-prc-cng-is-not-a-function-in-firefox-uncaught-typeerror-object) –
Quentin