URLのフラグメントを含むリンクのフラグメント内の一致を見つけて、リンクの親を強調表示するにはどうすればよいですか?URLのフラグメントとリンクのフラグメントをjqueryで照合しますか?
HTML、
<div class="item">
<a href="http://example.come/#/story/article-1/">Link 1</a>
</div>
<div class="item">
<a href="http://example.come/#/story/article-2/">Link 2</a>
</div>
<div class="item">
<a href="http://example.come/#/story/article-3/">Link 3</a>
</div>
<div class="item">
<a href="http://example.come/#/story/article-4/">Link 4</a>
</div>
jqueryの、だから、
//var fragment = location.hash;
fragment = '#/story/article-3/';
string = $('.item').find('a').attr('href');
array_string = string.split('#');
last_item = array_string[array_string.length - 1];
if(fragment == '#'+last_item)
{
alert('match!');
// this is my theory... but I don't know how to get the object that matches the fragment.
match_object.parents().css({background:'red'});
}
、この場合には、リンク3のコンテナ要素が強調表示されます。
はあなたにLoktarに感謝します! – laukok