html中: localhost/index.html#page1 ,#号问题?

localhost/index.html#page1

index.html中有:

 <a class=“a1” href="#page1"></a>
<a class=“a2” href="#page2"></a>

<div class="p1"></div>
<div class="p1"></div>

问题:localhost/index.html#page1 访问该链接,如何使页面呈现选中a1的状态?
注: 就是类似tab的切换,但是要通过localhost/index.html#page1连接来控制tab的选中状态。 求高手指点一下 3q。

通过获取URL的锚点值,然后判断切换不同的tab
请参考,http://www.jianshu.com/p/999906b4f120

alert(location.hash)//这个就是#xxx这个值,自己依据获取到的值执行tab的选中