Function
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| /**
* 获取get参数
* @param {String} str
* @param {String} variable
*/
function getQueryVariable(str, variable) {
var vars = str.split("&");
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split("=");
if (pair[0] == variable) {
return pair[1];
}
}
return false;
}
|
使用实例
url: https://pal.run/?key=pal&key2=run
1
2
3
4
5
| 调用: getQueryVariable(window.location.search.substring(1), "key");
返回: "pal";
调用: getQueryVariable(window.location.search.substring(1), "key2");
返回: "run";
|