获取路由地址上的参数值

写一个函数

function getUrlKey(name){
    return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) || [, ""])[1].replace(/\+/g, '%20')) || null
}

name为参数名,以下是调用例子

getUrlKey(‘userid’)

发布了13 篇原创文章 · 获赞 12 · 访问量 1437

猜你喜欢

转载自blog.csdn.net/weixin_44014980/article/details/102483756