문제

나는 이상한 실패에 빠져있다. 앵커 요소에 ID와 이름 속성이 모두 있으면 document.getElementById가 실패한 것 같습니다. 이름을 제거하면 작동합니다. Firefox 3.5 (최신)에서 이것을보고 있지만 아직 다른 브라우저를 확인하지 않았습니다.

이것은 버그입니까 아니면 의도적입니까?

도움이 되었습니까?

해결책

나는 그런 버그에 대해 들어 본 적이 없어서 그것을 재현하려고 시도했고 실패했습니다. 이것은 당신이 문제를 잘못 진단했거나 적어도 그것에 대한 정보를 충분히 제공하지 않았 음을 나타냅니다.

Firefox 3.5와 다음 코드로 테스트했습니다.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">
<title>Test of getElementById with named anchors</title>
<h1>Test of getElementById with named anchors</h1>

<h2><a name="one" id="one">First section</a></h2>
<p>The quick brown fox</p>

<h2><a name="two" id="second">Second section</a></h2>
<p>The quick brown fox</p>

<script type="text/javascript">    
if (document.getElementById('one')) {
        document.write("<p>First section found - id matches name<\/p>");
}

if (document.getElementById('second')) {
        document.write("<p>Second section found - id does not match name<\/p>");
}
</script>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top