• js正则获取url参数,包含hash[#]和search[?]两种通用


    function getQueryString(name) { 
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); 
    var r = (window.location.hash || window.location.search).substr(1).match(reg); 
    if (r != null) return unescape(r[2]); return null; 
    }
    

      

    调用:

    getQueryString(参数)
    

      

    更新:

    const getUrlparam = (param) => {
        const reg = new RegExp('(^|&)' + param + '=([^&]*)(&|$)');
        const r = window.location.search.substr(1).match(reg) || window.location.hash.substring((window.location.hash.search(/?/)) + 1).match(reg);
        if (r != null) {
            return decodeURIComponent(r[2]);
        }
    };
  • 相关阅读:
    P4999 烦人的数学作业
    P3413 SAC#1
    P2657 [SCOI2009]windy数
    P2602 [ZJOI2010]数字计数
    JSOI2007 建筑抢修
    CF161B Discounts
    Description
    Street Numbers
    Pizza Cutting
    Supermean
  • 原文地址:https://www.cnblogs.com/webSong/p/9233374.html
Copyright © 2020-2023  润新知