热搜: fiddler git ip 代理
历史搜索

javascript从 URL 获取查询参数

游客2024-12-21 07:30:01

js 从 URL 获取查询参数:

function getParameterByName(name, url) {
    if (!url) url = window.location.href;
    name = name.replace(/[[]]/g, "\$&");
    var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
    results = regex.exec(url);
    if (!results) return null;
    if (!results[2]) return '';
    return decodeURIComponent(results[2].replace(/+/g, " "));
}
标签:JavaScrip