location.href 与 location.hash
this.hash 获取或设置标签值(jquery)
(2015-03-03 15:34:13)使用出处:
this.hash含义:
location是javascript里边管理地址栏的内置对象,比如location.href就管理页面的url,用location.href=url就可以直接将页面重定向url。而location.hash则可以用来获取或设置页面的标签值,也就是锚链接的值。比如http://domain/#admin的location.hash="#admin"。
this.hash:获取当前链接的标签值:
location.hash
综:window.location.href表示重定向,后面跟着的是完整的url地址,与其相似的还有window.location.hash,
下面来比较window.location.href和window.locaiton.hash的区别。
(1)window.location.href
得到和使用的是完整的url,比如window.location.href="www.baidu.com”表示的是重新定向,页面跳转
到新的页面。也可以通过window.location.href得到a标签的完整的href,比如<a href="#book">如果使用href,那
么可以得到完整的链接(url)
(2)window.location.hash
得到的是锚链接。相比如href,通过window.location.hash并不会跳转到新的链接,只会在当前链接里面
改变锚链。并且如果有<a href="#book">通过window.location.hash得不到完整的链接(URL),仅仅得到#book.原文