“window.location.href”的区别是什么?和“window.location.hash”? [英] What is the difference between "window.location.href" and "window.location.hash"?

查看:162
本文介绍了“window.location.href”的区别是什么?和“window.location.hash”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我学习了window.location.hash new,并在我的jquery代码中尝试了,而不是window.location.href,并且它们都给出了相同的结果。

I learned "window.location.hash" new and tried in my jquery code instead of "window.location.href" and both of them gave same results.

代码在这里:

Code is here :

window.location.href = ($(e.currentTarget).attr("href"));
window.location.hash = ($(e.currentTarget).attr("href"));

它们有什么不同?

What is the difference between them?

推荐答案

对于像 http:// [www.example.com]:80 / search?q = devmo#test

散列会返回#符号后的网址部分,包括#符号。
您可以监听hashchange事件,以获得支持浏览器中散列更改的通知。

hash return the part of the URL that follows the # symbol, including the # symbol. You can listen for the hashchange event to get notified of changes to the hash in supporting browsers.

Returns: #test

href 返回整个网址。

href returns the entire URL.

Returns: http://[www.example.com]:80/search?q=devmo#test

阅读更多内容

这篇关于“window.location.href”的区别是什么?和“window.location.hash”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆