私は奇妙な失敗に遭遇しています。アンカー要素にID属性とNAME属性の両方がある場合、document.getElementByIdが失敗するようです。NAMEを削除すると、機能します。これはFirefox3.5(最新)で見られますが、他のブラウザはまだチェックしていません。
これはバグですか、それとも意図的なものですか?
私は奇妙な失敗に遭遇しています。アンカー要素にID属性とNAME属性の両方がある場合、document.getElementByIdが失敗するようです。NAMEを削除すると、機能します。これはFirefox3.5(最新)で見られますが、他のブラウザはまだチェックしていません。
これはバグですか、それとも意図的なものですか?
そのようなバグを聞いたことがないので、再現しようとして失敗しました。これは、問題を誤診したか、少なくとも問題に関する十分な情報を提供していないことを示しています。
Firefox3.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>