queryURLparams 工作中常常会遇到获取url地址参数的例子,记录一下封装好的方法,好记性不如烂笔头
const url = 'http://www.baidu.com/index.html?lx=1&name=zhangsan&age=10#box';
function queryUrlParams(url){
let askIn = url.indexOf('?');
let wellIn = url.indexOf('#');
let askText ="";
let wellText = "";
wellIn===-1?wellIn = url.length:null;
askIn>=0?askText = url.substring(askIn+1,wellIn):null;
wellText=url.substring(wellIn+1);
let result ={};
wellText!==""?result['HASH'] = wellText:null;
if(askText!==""){
let ary = askText.split('&');
ary.forEach(item => {
let itemAry = item.split('=');
result[itemAry[0]] = itemAry[1];
});
}
return result;
}