js中的location各种属性

一、hash设置或返回从井号 (#) 开始的 URL(锚)。

URL 是: http://example.com:1234/test.htm#part2

location.hash-------------#part2

二、host设置或返回主机名和当前 URL 的端口号。

URL 是: http://example.com:1234/test.htm#part2

location.host------------example.com:1234

三、hostname设置或返回当前 URL 的主机名。

URL 是: http://example.com:1234/test.htm#part2:

location.hostname------------example.com

四、href设置或返回完整的 URL。

URL 是: http://example.com:1234/test.htm#part2:

location.href-------------http://example.com:1234/test.htm#part2

五、pathname设置或返回当前 URL 的路径部分。

URL 是: http://example.com:1234/test/test.htm#part2:

location.pathname-------------/test/test.htm

六、port设置或返回当前 URL 的端口号。

URL 是: http://example.com:1234/test.htm#part2:

location.port-------------1234

七、protocol设置或返回当前 URL 的协议。

URL 是: http://example.com:1234/test.htm#part2:

location.protocol-------------http:

八、search设置或返回从问号 (?) 开始的 URL(查询部分)。

URL 是: http://www.w3school.com.cn/tiy/t.asp?f=hdom_loc_search

location.search-------------?f=hdom_loc_search

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容