how to get GET variable's value in javascript?
本问题已经有最佳答案,请猛点这里访问。
Possible Duplicate:
Get query string values in JavaScript
如何获取javascript中的get变量?
我想在jquery函数中传递它。
1 2 3 4 5 6 7 | function updateTabs(){ //var number=$_GET['number']; how can i do this? alert(number); $("#tabs" ).tabs({ selected: number }); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | 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']); |
写:
1 2 | var $_GET=[]; window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi,function(a,name,value){$_GET[name]=value;}); |
然后是
试试这个
1 2 3 4 5 6 7 8 9 | 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]+"'") } } |