location.search获取get参数截取URL参数

var queryArgs = location.search.slice(1);
queryArgs =http://localhost/case-operation.html?name=record&id=123"

那么console.log(queryArgs )
输出

?name=record&id=123

处理的参数的话一般会使用

location.search.slice(1);

直接赋值。另外补充for循环处理参数的简单例子:

 var arr = queryArgs.split('&');
 for (let item of arr) {
   let a = item.split('=');
   o[a[0]] = a[1];
 }

你可能感兴趣的:(location.search获取get参数截取URL参数)