javascript - 如何从 URL 中提取 "search term"?

标签 javascript

如何从以下 URL 中提取“test”?

http://www.example.com/index.php?q=test&=Go

我找到了提取路径 (window.location.pathname) 的脚本,但我找不到或弄清楚如何提取或拆分 URL。

-本

最佳答案

var m = window.location.search.match(/q=([^&]*)/);

if (m) { 
    alert(m[1]); // => alerts "test"
} 

关于javascript - 如何从 URL 中提取 "search term"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5176115/

相关文章:

javascript - Bootstrap 4 : Fixing and fading in footer at the bottom of the page

javascript - 如何在客户端处理多个请求/API 调用并行的 JWT 刷新 token ?

javascript函数只传递一个特定参数

javascript - 使用 Postman 的 Salesforce 集成 INVALID_SESSION_ID

javascript - 将事件绑定(bind)到 openlayer3 map

javascript - Angular5 - 使用无效数据调用错误 : Function DocumentReference. set()。数据必须是对象,但它是:自定义 PlatformModel 对象

javascript - AngularJS $scope.$apply() 困境

javascript - 使用鼠标在浏览器中使用 three.js 操作对象

javascript - Angular 指令 - 将绝对定位的死者宽度设置为根的宽度

javascript - JQuery - 字符串列表