如何获取get变量's值

how to get GET variable's value in javascript?

本文关键字:变量 get 何获取 获取      更新时间:2023-09-26

可能重复:
在JavaScript 中获取查询字符串值

如何在javascript中获取get变量?

我想在jquery函数中传递它。

function updateTabs(){
            //var number=$_GET['number']; how can i do this?
        alert(number);
        $( "#tabs" ).tabs({ selected: number });
    }
var $_GET = {};
if(document.location.toString().indexOf('?') !== -1) {
    var query = document.location
                   .toString()
                   // get the query string
                   .replace(/^.*?'?/, '')
                   // and remove any existing hash string (thanks, @vrijdenker)
                   .replace(/#.*$/, '')
                   .split('&');
    for(var i=0, l=query.length; i<l; i++) {
       var aux = decodeURIComponent(query[i]).split('=');
       $_GET[aux[0]] = aux[1];
    }
}
//get the 'index' query parameter
alert($_GET['index']);

写入:

var $_GET=[];
window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi,function(a,name,value){$_GET[name]=value;});

然后$_GET['number']

试试这个

if (location.search != "")
{
    var x = location.search.substr(1).split(";")
    for (var i=0; i<x.length; i++)
    {
         var y = x[i].split("=");
         alert("Key '" + y[0] + "' has the content '" + y[1]+"'")
    }
}