- hash,返回一个url的一个锚部分。返回一个 URL 的主要部分。假设当前的 URL 是 http://www.runoob.com/test.htm#PART2:输出#part2
- host,返回一个url的主机名和端口号。document.write(location.host);返回www.baidu.com
- hostname,返回主机名。document.write(location.hostname);返回www.baidu.com
- href,返回完整的url,document.write(location.href);返回https://www.runoob.com/jsref/prop-loc-href.html
- pathname,返回url的路径部分,document.write(location.pathname);返回/jsref/prop-loc-pathname.html
- port,返回一个URL服务器使用的端口号,document.write(location.port);返回80
- protocol,返回当前url协议,document.write(location.protocol);返回https:
- search,返回url的查询部分,document.write(location.search);返回?email=someone@example.com
本文介绍了JavaScript中location对象的几个关键属性,如hash用于获取URL的锚部分,host返回URL的主机名和端口号,hostname返回主机名,href返回完整URL,pathname返回URL路径,port返回端口号,protocol返回URL协议,而search则返回查询参数部分。这些属性在网页交互和URL操作中扮演重要角色。

被折叠的 条评论
为什么被折叠?



