問一個沒有可能結束的問題是如何從URL獲取變量。在我所有的搜索中,我發現了幾種非常好的方法從url中獲取A=aValue
。如何從JavaScript中的URL獲取多個具有相同名稱的參數
但我的問題是 我需要
?Company=FLHS&Device=Crosstown_PCC_01&A=aValue&A=secondAValue
我需要的兩個A url中的數組,我需要知道aValue
是第一個和secondAValue
是第二
我有jQuery Mobile。
更新
原來這就是我現在
var urlParamDevice = getURLParameter('DeviceID');
function getURLParameter(name) {
return decodeURI(
(RegExp(name + '=' + '(.+?)(&|$)').exec(location.search) || [, null])[1]
);
的getURLParameter(名稱)需要一點更穩健。
更新2,2014年3月7日 這裏是我想出了從建議的答案
function getQueryParams(name) {
qs = location.search;
var params = [];
var tokens;
var re = /[?&]?([^=]+)=([^&]*)/g;
while (tokens = re.exec(qs))
{
if (decodeURIComponent(tokens[1]) == name)
params.push(decodeURIComponent(tokens[2]));
}
return params;
}
有一些傳遞數組(或任何其他對象)作爲參數的示例:https://api.jquery.com/jQuery.param/ – Rainbolt
謝謝,試圖從URL中獲取數組而不通過一個。 –