从地址栏中删除#fragment标识符

tho*_*hom 8 javascript jquery

嗨,我希望有人可以帮忙.我想隐藏地址栏中的片段标识符,而不是:

www.mydomain.com/example.html#something

我得到:

www.mydomain.com/example.html

当我点击一个锚标签.

我看了很多相关的问题和论坛,但仍然无法弄明白.我很确定我应该使用以下内容:

window.location.href.replace(/#.*/,''); //and or .hash
Run Code Online (Sandbox Code Playgroud)

放就是想不出来.

localScroll插件允许您隐藏或保留标识符,默认情况下它们是隐藏的.我认为很多画廊插件也有类似的选择.

但是当我尝试自己做的时候(一点新手)我发疯到没有结果.

下面是我希望它可以使用的一些基本示例脚本:

<style>
.wrap{
width:300px;
height:200px;
margin:auto;
}

.box{
width:300px;
height:200px;
position:absolute;
display:none;
}

#one{background:red;}
#two{background:blue;}
#three{background:green;}

.load{display:block;}
</style>


<body>
<ul>
    <li><a href="#one">One</a></li>
    <li><a href="#two">Two</a></li>
    <li><a href="#three">Three</a></li>
</ul>

<div class="wrap">
    <div id="one" class="box load">This is Box 1</div>
    <div id="two" class="box">This is Box 2</div>
    <div id="three" class="box">This is Box 3</div>
</div>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script>
$(document).ready(function() {

$("ul li a").click(function(){

       $("div.box").fadeOut(1000);

       $($(this).attr('href')).fadeIn(1000);

    });
});
</script>
</body>
Run Code Online (Sandbox Code Playgroud)

Ric*_*lli 19

return false;
Run Code Online (Sandbox Code Playgroud)

在点击功能结束时,它将停止此事件传播