前端 url地址参数解析 url(window.location.href)

325 阅读1分钟

记录一下没啥技术含量

addressResolution(url=window.location.href){  
    if(!url|| typeof url!=='string'){  
        return '地址解析格式错误'  
    }  
    let a = url.split('?')[1]||'';  
    if(a!==''&& (a.split('&').length!==0||a.split('&&').length!==0)){  
        let b = a.split('&')||a.split('&&');  
        let c = {};  
        b.forEach(item=>{  
            let key = item.split('=')[0];  
            let value = item.split('=')[1];  
            c[key] = value   
        });  
        return c  
    }else{  
        return 'error'  
    }  
}
直接调用

chatgpt 对话小程序 ai对话 爱画图 扫码体验

gh_fee1287c2853_258.jpg