Javascriptを - アンカーはまた、name属性を持っている場合は失敗しgetElementByIdを

StackOverflow https://stackoverflow.com/questions/1289967

質問

私は奇妙な失敗に実行していますよ。私がアンカー要素にIDとNAME属性の両方を持っている場合、の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