早睡早起,方能养生!
Sleep early rise early, square can preserve one's health!

JS获取url参数

super
2019-11-22 12:01
views 605
function getQueryString(name)
{
    const reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    const urlObj = window.location;
    var r = urlObj.href.indexOf('#') > -1 ? urlObj.hash.split("?")[1].match(reg) : urlObj.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]); return null;
}
//获取参数 code:
alert(getQueryString("code"));

 

 


分享
0 条讨论
top