使用javascript获取包含所有字符的查询字符串参数
我需要按名称获取查询字符串参数 我的参数包括所有类型的字符,包括“=”符号 以下是一个例子: 我试过:使用javascript获取包含所有字符的查询字符串参数,javascript,query-string,Javascript,Query String,我需要按名称获取查询字符串参数 我的参数包括所有类型的字符,包括“=”符号 以下是一个例子: 我试过: function getParameterByName(name) { var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search); return match && decodeURIComponent(match[1].replace(/\+/g, ' ')); }
function getParameterByName(name) {
var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search);
return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
}
function getParameterByName(key) {
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for (var i = 0; i < hashes.length; i++) {
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars[key];
}
但它将“+”符号替换为空格:
“代码”:“Ippr7HP/Fad2q3kKMehQtVYnbFcZp h4ECS RCQmN KrcAM8N4tdeNciNEXlwkhnjF3tZgez1/A1CA1018UXPodGenPCYTJZSUPJSFUSMYUS1HORXY04WKLGIYW031 LAYXLDGHGJO 0S7SUD7LWFMAP8B3EN//YCBEQNM6RVC7AHMS77NG6I6P6MSCBEFU/RNJ5LY7TQW==
我试过:
function getParameterByName(name) {
var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search);
return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
}
function getParameterByName(key) {
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for (var i = 0; i < hashes.length; i++) {
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars[key];
}
函数getParameterByName(键){
var vars=[],散列;
var hashes=window.location.href.slice(window.location.href.indexOf('?')+1).split('&');
for(var i=0;i
但这不包括“=”符号
有什么建议吗?您的第二次尝试已经足够接近了,您只需要在
之后重新加入值部分。拆分('=')
函数getParameterByName(parameterName){
var query=window.location.search.substring(1);
var queryParameters={};
var vars=query.split('&');
对于(变量i=0;ivar vars=window.location.href.slice(window.location.href.indexOf('?')+1)。拆分('&');
还有更短的方法吗?非常感谢!