js 获取对应的url参数

举例:http://localhost:5000/?sss=sdf&fdd=123

1、设置或获取整个 URL 为字符串

window.location.href  

值:  http://localhost:5000/?sss=sdf&fdd=123

2、设置或获取 URL 的协议部分

window.location.protocol

值:http:

3、设置或获取 URL 的主机部分

window.location.host

值:localhost:5000

4、设置或获取与 URL 关联的端口号码

window.location.port

值:5000

5、设置或获取与 URL 的路径部分(就是文件地址)

window.location.pathname

值:/

6、设置或获取 href 属性中跟在问号后面的部分

window.location.search

值:?sss=sdf&fdd=123

7、设置或获取 href 属性中在井号“#”后面的分段

window.location.hash

值:空

若有疑问可以留言。

原文地址:https://www.cnblogs.com/zxs-onestar/p/12082535.html