【问题标题】:How to retrieve value in URL and store it in variable [duplicate]如何检索 URL 中的值并将其存储在变量中 [重复]
【发布时间】:2015-07-13 16:03:47
【问题描述】:

我有一个如下所示的网址 http://www.grcparfum.it/home.php?section=letteradelpresidente&lang=eng

此网址中的语言是英文

lang=eng​​p>

当lang不同时我想调用不同的JS文件

【问题讨论】:

标签: javascript php request.querystring


【解决方案1】:

这是一个可以为你获取JS中查询字符串变量的函数:

function $_GET(q){
    var $_GET = {};
    if(document.location.toString().indexOf('?') !== -1){
        var query = document.location
                       .toString()
                       .replace(/^.*?\?/, '')//Get the query string
                       .replace(/#.*$/, '')//and remove any existing hash string
                       .split('&');
        for(var i=0, l=query.length; i<l; i++){
           var aux = decodeURIComponent(query[i]).split('=');
           $_GET[aux[0]] = aux[1];
        }
    }
    return $_GET[q];
}

这有帮助吗?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-19
    • 2018-11-13
    • 1970-01-01
    • 2013-07-28
    • 2021-07-16
    • 1970-01-01
    相关资源
    最近更新 更多