1)index.html
ブロックのあるページがあります:
<body>
<div id="action1">One</div>
<div id="action2">Two</div>
<div id="action3">Three</div>
</body>
2) CSS
body div { color: blue; }
body div.current { font-weight: bold; color: red; }
3)index.html
いくつかのターゲットへのリンクがあるその他のページ:
<a href="index.html#action1">Link to One</a><br/>
<a href="index.html#action2">Link to Two</a><br/>
<a href="index.html#action3">Link to Three</a><br/>
問題は、ページ上の現在のリンク ターゲットをキャッチindex.html
し、ターゲット ブロックに追加のクラスを与える方法です。
開いているページの現在のリンクが の場合index.html#action1
、クラス.current
を追加すると<div id="action1">One</div>
- になります<div id="action1" class="current">One</div>
もしindex.html#action2
-><div id="action2" class="current">Two</div>
等々。
- 小切手 #
target
- 小切手
id
- if
target
=id
addClass("current") for ブロックid
ありがとう。