js获取url后面的参数


 

let url = window.location.href;//http://localhost:3000/edu/edu_teacher?type=2&a=3
if(url.indexOf('?') != -1){
    let obj = {};
    let arr = url.slice(url.indexOf('?')+1).split('&');
    arr.forEach(item => {
        let param = item.split('=');
        obj[param[0]] = param[1];
    })
    console.log(obj);//{type: "2", a: "3"}
    alert(obj.type);
    return obj;
}else{
    console.log('没有参数');
    alert('没有参数');
    return null;
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM