how to get GET variable's value in javascript?

2019-01-17 13:07发布

问题:

Possible Duplicate:
Get query string values in JavaScript

how can i get the get variable in javascript?

i want to pass it in jquery function.

function updateTabs(){

            //var number=$_GET['number']; how can i do this?
        alert(number);
        $( "#tabs" ).tabs({ selected: number });

    }

回答1:

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']);


回答2:

Write:

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

Then $_GET['number']



回答3:

Refer this Link . OR Try this

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]+"'")
    }
}