Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
你能帮我从 URL 中获取一些参数吗?
网址应为以下形式:http.www.lolilol.com/gallery/Param1/Param2/Param3/
http.www.lolilol.com/gallery/Param1/Param2/Param3/
我需要得到Param1和。Param2Param3
Param1
Param2
Param3
一个简单的解决方案:
var params = document.location.pathname.split('/').slice(2);
这给了你数组["Param1", "Param2", "Param3"]
["Param1", "Param2", "Param3"]
正则表达式会http://www\.lolilol\.com/gallery/(.*)/(.*)/(.*)/假设你的意思http://www.lolilol.com/gallery/Param1/Param2/Param3/
http://www\.lolilol\.com/gallery/(.*)/(.*)/(.*)/
http://www.lolilol.com/gallery/Param1/Param2/Param3/