“window.location.href”和“window.location.hash”有什么区别
What is the difference between "window.location.href" and "window.location.hash"?
我学习了"window.location.hash">,并尝试在我的jquery代码中而不是"window.location.href">,它们都给出了相同的结果。
代码在这里:
window.location.href = ($(e.currentTarget).attr("href"));
window.location.hash = ($(e.currentTarget).attr("href"));
它们之间有什么区别?
对于像 http://[www.example.com]:80/search?q=devmo#test
这样的网址
-
hash
- 返回 URL 中#
符号后面的部分,包括#
符号。您可以侦听hashchange
事件,以便在支持的浏览器中收到哈希更改的通知。Returns: #test
-
href
- 返回整个 URL。Returns: http://[www.example.com]:80/search?q=devmo#test
阅读更多
例如
http://stackoverflow.com/#Page
对其进行测试
href = http://stackoverflow.com/#Page
hash = #Page
href 是网址
哈希只是 url 后面的锚点
http://www.xxxxxxxx.com#anchor
http://www.xxxxxxxx.com#anchor is the href
"#anchor"是哈希
hash 属性返回 URL 的锚点部分,包括哈希符号 (#(。
hash
和 href
都是 window.location
对象的属性。 hash
是 URL 的一部分,从 #
开始(如果没有#
,则为空字符串(,而 href
是整个 URL 的字符串表示形式。
这是window.location.href
和window.location.hash
之间区别的简单示例
对于网址http://www.manm.com/member/#!create
:
- href:
http://www.manam.com/member/#!create
- 哈希:
#!create
相关文章:
- window.location替换并传递URL历史记录条目中的变量
- 可以<脚本类型=“;text/javascript”>window.location=“/"</
- window.location使用jquery mobile实现chrome跳转
- Windows.Open 在 window.Location 工作时不起作用
- 如何将所有作业自定义到window.location.href
- window.location未刷新到现有URL
- 如果window.location.href.indexOf('player=1')添加样式
- 在$state.go之后执行$window.location.reload(true)
- javascript window.location在检查firebug时给了我一个错误的url路径
- angularjs 中 $window.location.reload() 和 $route.reload() 之间的区
- 在AJAX中使用window.location.replace'成功'回调
- IE中不支持JQuery window.location.hash
- PhoneGap如何在更改window.location/document.location后保持Javascript的
- 如何在更改window.location后停止执行
- 警报中的window.location必须重定向到上一页
- 如何在窗体操作或window.location(PHP)中使用数据切换
- 正在将目标添加到window.location
- setInterval在window.location/window.open上中断
- window.location=window.location易受XSS影响
- internet explorer - IE javascript location, window.open