1
なぜこれをやっているのかは説明するのがむずかしいですが、URLの最後の部分を取り出してアンカータグの先頭に追加しようとしています。URLの終わりを抽出してhrefに追加する
http://www.website.com/page/home
だから、「ホーム」は、以下に終わるでしょう:
<div class="officeBtns">
<a class="linkbuttons locBtn" href="home#something1">Button1</a>
<a class="linkbuttons locBtn" href="home#something2">Button2</a>
<a class="linkbuttons locBtn" href="home#something3">Button3</a>
</div>
を私はまだ最後の「#something」が必要として全体のhrefを交換したくありません。 私はまた、例えば、URLの最後に何かを無視する必要が
http://www.website.com/page/home#blah
または
http://www.website.com/page/home?blah=blah
これまでのところ、これは私の未完成のコードです:
$(document).ready(function() {
var url = window.location.pathname,
urlRegExp = new RegExp(url == '/' ? window.location.origin + '/?$' : url.replace(/\/$/,''));
$('.officeBtns a').each(function(){
if(urlRegExp.test(this.href.replace(/\/$/,''))){
INSERT URL INTO HREF BEFORE THE #
}
});
});
おかげ
パターンの問題のようです。 #と#の間に最小限の部分を入れてみてください。または終わり。 –