js获取链接?后边的参数名称或者值,根据url ?后的参数做判断
程序员文章站
2024-02-17 23:43:16
...
var url = location.search; //获取url中"?"符后的字串 ,包括?
console.log(url);
function GetRequest() {
var url = location.search; //获取url中"?"符后的字串
var theRequest = new Object();
if(url.indexOf("?") != -1) {
var str = url.substr(1);
strs = str.split("&");
for(var i = 0; i < strs.length; i++) {
theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
}
}
return theRequest;
}
var Request = undefined;
Request = GetRequest();
console.log(Request);//最后获取的字段名+值
const keys= Object.keys(Request);
console.log(keys);//数组
console.log(keys[0]);//输出a
案例:
设计稿:
根据url后的参数判断状态为:已解决,未解决,全部;
var url = location.search; //获取url中"?"符后的字串 ,包括?
// console.log(url);
function GetRequest() {
var url = location.search; //获取url中"?"符后的字串
var theRequest = new Object();
if(url.indexOf("?") != -1) {
var str = url.substr(1);
strs = str.split("&");
for(var i = 0; i < strs.length; i++) {
theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
}
}
return theRequest;
}
var Request = undefined;
Request = GetRequest();
// console.log(Request);//最后获取的字段名+值
// const keys= Object.keys(Request);
// console.log(keys);//数组
// console.log(keys[0]);//输出a
let status = Request.status;
if(status == 2){
$('.tit05 .tit05div .zhuangtai').text('全部');
}else if(status == 1){
$('.tit05 .tit05div .zhuangtai').text('已解决');
}else{
$('.tit05 .tit05div .zhuangtai').text('未解决');
}
参考文章:
js获取链接?后边的参数名称或者值:https://www.cnblogs.com/zxcc/p/11454196.html
上一篇: java实现酒店管理系统