don*_*yor 59 javascript url uri
我有这个:
http://127.0.0.1:8000/found-locations/?state=--&km=km
Run Code Online (Sandbox Code Playgroud)
我要这个:
found-locations/?state=--&km=km
Run Code Online (Sandbox Code Playgroud)
我如何在JavaScript中执行此操作?
我试过window.location.href但它给了我整个网址
我试过window.location.pathname.substr(1)但它给了我found-locations/
Gum*_*mbo 91
使用location.pathname和location.search:
(location.pathname+location.search).substr(1)
Run Code Online (Sandbox Code Playgroud)
小智 41
window.location.pathname + window.location.search
Run Code Online (Sandbox Code Playgroud)
会得到你的基本网址/found-locations和查询字符串?state=--&km=km
如果您的 url 是字符串,则可以创建URL对象并使用pathname和search属性。
let strurl = 'http://www.test.com/param1/param2?test=abc';
let url = new URL(strurl)
let pathandQuery = url.pathname + url.search;
Run Code Online (Sandbox Code Playgroud)
let strurl = 'http://www.test.com/param1/param2?test=abc';
let url = new URL(strurl)
let pathandQuery = url.pathname + url.search;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
73860 次 |
| 最近记录: |