我有这个:
http://127.0.0.1:8000/found-locations/?state=--&km=km
我要这个:
found-locations/?state=--&km=km
我如何做到这一点在JavaScript?
我试图window.location.href
但它给我的整个URL
我试图window.location.pathname.substr(1)
但它给我found-locations/
我有这个:
http://127.0.0.1:8000/found-locations/?state=--&km=km
我要这个:
found-locations/?state=--&km=km
我如何做到这一点在JavaScript?
我试图window.location.href
但它给我的整个URL
我试图window.location.pathname.substr(1)
但它给我found-locations/
使用location.pathname
和location.search
:
(location.pathname+location.search).substr(1)
window.location.pathname + window.location.search
将让你的基础URL /found-locations
以及查询字符串?state=--&km=km
URI.js是一个很好的JavaScript库解析URI的。 它可以做什么,你有一个很好的流畅的语法要求。