如何从以下 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/