javascript - 使用 JavaScript 获取 URL 的特定部分

标签 javascript jquery

我是 JavaScript 新手,我需要帮助解决问题。

我有以下网址:

http://localhost/solo04/index.php?route=checkout/checkout#shipping-method

我只想获取 url 的那部分(route =checkout/checkout),该怎么做?

最佳答案

最简单的方法是使用regexsplit:

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);

列出了更多变体 How to get the value from the GET parameters?

关于javascript - 使用 JavaScript 获取 URL 的特定部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44438019/

相关文章:

javascript - 匹配多个相互依赖的可选字符

javascript - Jquery after() 引号异常

jquery - 删除附加数据 - jquery

javascript - 为什么函数会产生错误的解决方案

javascript - Visual Studio 2008 不在 JS 文件中显示我的 XML 注释

javascript - 在javascript中创建样式类

javascript - 你怎么知道你正在使用的 JavaScript 库在升级后是否会破坏你的代码?

jquery - 跟踪用户鼠标

jquery - 使用 JQuery .ajax,使用 jquery 'json' 与 'text' 时不会调用 Success 方法

jquery - 将每个嵌套在 jQuery 模板中