我是 JavaScript 新手,我需要帮助解决问题。
我有以下网址:
http://localhost/solo04/index.php?route=checkout/checkout#shipping-method
我只想获取 url 的那部分(route =checkout/checkout),该怎么做?
最佳答案
最简单的方法是使用regex
或split
:
url = "http://localhost/solo04/index.php?Route=checkout/checkout#shipping-method";
lastPart = url.split('?')[1]; // grabs the part on the right of the ?
console.log(lastPart);
关于javascript - 使用 JavaScript 获取 URL 的特定部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44438019/