You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.5 KiB
Plaintext
59 lines
1.5 KiB
Plaintext
//获取QueryString的数组
|
|
function getQueryString() {
|
|
// eslint-disable-next-line no-useless-escape
|
|
var result = location.search.match(new RegExp("[\?\&][^\?\&]+=[^\?\&]+", "g"));
|
|
for (var i = 0; i < result.length; i++) {
|
|
result[i] = result[i].substring(1);
|
|
}
|
|
return result;
|
|
}
|
|
//根据QueryString参数名称获取值
|
|
function getQueryStringByName(name) {
|
|
// eslint-disable-next-line no-useless-escape
|
|
var result = location.search.match(new RegExp("[\?\&]" + name + "=([^\&]+)", "i"));
|
|
if (result == null || result.length < 1) {
|
|
return "";
|
|
}
|
|
return result[1];
|
|
}
|
|
//根据QueryString参数索引获取值
|
|
function getQueryStringByIndex(index) {
|
|
if (index == null) {
|
|
return "";
|
|
}
|
|
var queryStringList = getQueryString();
|
|
if (index >= queryStringList.length) {
|
|
return "";
|
|
}
|
|
var result = queryStringList[index];
|
|
var startIndex = result.indexOf("=") + 1;
|
|
result = result.substring(startIndex);
|
|
return result;
|
|
}
|
|
//Other
|
|
function GetQueryString(name) {
|
|
|
|
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
|
|
|
|
var r = window.location.search.substr(1).match(reg);
|
|
|
|
if (r != null) return decodeURI(r[2]); return null;
|
|
|
|
}
|
|
|
|
//修改URL参数值
|
|
function replaceParamVal(url, paramName, replaceWith) {
|
|
var re = eval('/(' + paramName + '=)([^&]*)/gi');
|
|
var nUrl = url.replace(re, paramName + '=' + replaceWith);
|
|
return nUrl;
|
|
}
|
|
export {
|
|
getQueryString,
|
|
getQueryStringByName,
|
|
getQueryStringByIndex,
|
|
GetQueryString,
|
|
replaceParamVal
|
|
}
|
|
|
|
|