/**
*queryURLParam :获取URL地址中问号传参的信息和哈希值
*@params
* url [string] 要解析的URL字符串
*@return
* [object] 包含参数和哈希值信息的对象
*by JJbang on 20191128
*/
function queryURLParams(url) {
//获取?和#后面的信息
let askIn = url.indexOf('?'),
wellIn = url.indexOf('#'),
askText = '',
wellText = '';
// #不存在
wellIn === -1 ? wellIn = url.length : null;
// ?存在
askIn >= 0 ? askText = url.substring(askIn + 1, wellIn) : null;
wellText = url.substring(wellIn + 1);
//2.获取每一部分信息
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];
});
}
r
queryURLParam获取URL地址中问号传参的信息和哈希值
最新推荐文章于 2023-12-27 20:45:10 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)