验证中...
Languages: JavaScript
Categories: JavaScript 工具
Latest update 2019-05-16 14:39
gistfile1.txt
Raw Copy
根据url获取参数
var urlParams = new URLSearchParams(window.location.search);
console.log(urlParams.has('post')); // true
console.log(urlParams.get('action')); // "edit" 写入对应的字段名
console.log(urlParams.getAll('action')); // ["edit"]
console.log(urlParams.toString()); // "?post=1234&action=edit"
console.log(urlParams.append('active', '1')); // "?post=1234&action=edit&active=1" 添加
url获取参数 返回数组对象
function search(){
var Url = window.location.search;
Url = Url.substring(1, Url.length);
var obj = new Object();
if(Url !==""){
var arr = Url.split("&");
for (var i = 0; i < arr.length; i++) {
var tmp_arr = arr[i].split("=");
obj[decodeURIComponent(tmp_arr[0])] = decodeURIComponent(tmp_arr[1]);
}
}
return obj;
};search()
最简洁的url参数获取
q={};location.search.replace(/([^?&=]+)=([^&]+)/g,(_,k,v)=>q[k]=v);q;

Comment list( 0 )

You need to Sign in for post a comment

Help Search