我从后端获取此网址,并且只需要从这里获取一个参数(游戏编号)
https://www.example.com/#/?category=all&provider=all&game=3189&type=fun
如何在控制器中获得游戏编号(3189)?
它不是$ location
答案 0 :(得分:2)
function GetParameter(parameterName) {
var result = null;
var tmp = [];
var items = location.href.substr(1).split("&");
for (var index = 0; index < items.length; index++) {
tmp = items[index].split("=");
if (tmp[0] === parameterName) result = decodeURIComponent(tmp[1]);
}
return result;
}
function GetParameterFromString(parameterName, url) {
var result = null;
var tmp = [];
var items = url.split("&");
for (var index = 0; index < items.length; index++) {
tmp = items[index].split("=");
if (tmp[0] === parameterName) result = decodeURIComponent(tmp[1]);
}
return result;
}
然后你会打电话给
var url = "example.com/#/?category=all&provider=all&game=3189&type=fun";
var gameNumber = GetParameterFromString("game" url);