多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
~~~ /* * queryURLParams:获取地址栏中问号传参的信息 * 'http://www.zhufengpeixun.cn/?lx=1&name=JS&from=baidu#video' 解析问号和井号后面的值,最后得到一个包含信息的对象 => { lx:1, name:'JS', from:'baidu', HASH:'video' } */ /* function queryURLParams(url) { // 1.首先获取问号和井号后面的值 let askIndex = url.indexOf('?'), polIndex = url.lastIndexOf('#'); let askText = url.substring(askIndex + 1, polIndex), polText = url.substring(polIndex + 1); // console.log(askText, polText); //=>"lx=1&name=JS&from=baidu" "video" // 2.把获取到的结果进行解析,最后拼成一个对象返回 let obj = {}; // 处理哈希值(井号后面的值) polText.length > 0 ? obj['HASH'] = polText : null; // 问号参数的处理 if (askText) { // askText.split('&') =>["lx=1","name=JS","from=baidu"] askText.split('&').forEach(item => { // item:循环数组中的每一项 let arr = item.split('='), //=>"lx=1" => ["lx",1] key = arr[0], value = arr[1]; obj[key] = value; }); } return obj; } */ /* function queryURLParams(url) { // 1.首选获取问号和井号后面的值 let askIndex = url.indexOf('?'), polIndex = url.lastIndexOf('#'); let askText = url.substring(askIndex + 1, polIndex), polText = url.substring(polIndex + 1); //=>"lx=1&name=JS&from=baidu" "video" // 2.把获取到的结果进行解析,最后拼成一个对象返回 let obj = {}; // 处理哈希值(井号后面的值) polText.length > 0 ? obj['HASH'] = polText : null; // 问号参数的处理 if (askText) { let askArr = askText.split('&'); //=>["lx=1","name=JS","from=baidu"] for (let i = 0; i < askArr.length; i++) { let item = askArr[i]; let itemArr = item.split('='); //=>"lx=1" ["lx","1"] obj[itemArr[0]] = itemArr[1]; } } return obj; } */ /* function queryURLParams(url) { let askIndex = url.indexOf('?'), polIndex = url.lastIndexOf('#'), askText = '', polText = ''; polIndex === -1 ? polIndex = url.length : null; polText = url.substring(polIndex + 1); if (askIndex > -1) { askText = url.substring(askIndex + 1, polIndex); } let obj = {}; polText.length > 0 ? obj['HASH'] = polText : null; if (askText) { askText.split('&').forEach(item => { let arr = item.split('='); obj[arr[0]] = arr[1]; }); } return obj; } */ // let result = queryURLParams('http://www.zhufengpeixun.cn/?lx=1&name=JS&from=baidu#video'); // let result = queryURLParams('http://www.zhufengpeixun.cn/?lx=1&name=JS&from=baidu'); // let result = queryURLParams('http://www.zhufengpeixun.cn/#video'); // let result = queryURLParams('http://www.zhufengpeixun.cn/'); // console.log(result); ~~~