1. const getUrlParam = (name) => {
    2. let reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)')
    3. if( !window.location.href.includes('?')) return
    4. let r = window.location.href.split("?")[1].match(reg)
    5. if (r != null) return unescape(r[2])
    6. return null
    7. }
    8. //备注:window.location.search有时候获取不到值, window.location.href.split("?")[1]等价于
    9. //window.location.search.substr(1)
    10. “(^|&)” + name + "=([^&]*)(&|$)的含义 :
    11. 匹配以&name=开头或者空白name=开头中间为任意多个除了&以外的字符 一旦遇到&
    12. 或者空白就中止取值

    image.png