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.
我到处搜索,但我找不到一篇在一行中获取查询字符串值的帖子,而无需自己编写函数......
不是从 JQuery 中内置的查询字符串中获取值吗?
使用正则表达式搜索键,然后搜索对应的值。jsfiddle
var value = location.search.match(new RegExp(key + "=(.*?)($|\&)", "i"))[1];
以 开头window.location.href,然后使用字符串命令在第一个 '?' 处创建子字符串。
window.location.href