如何在javascript中获取GET变量的值? [英] how to get GET variable's value in javascript?
本文介绍了如何在javascript中获取GET变量的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能存在重复:
在JavaScript中获取查询字符串值
如何可以我在javascript中获取变量?
我想在jquery函数中传递它。
function updateTabs(){
// var number = $ _ GET ['number'];我怎样才能做到这一点?
alert(number);
$(#tabs).tabs({selected:number});
$ b
解决方案
var $ _GET = {};
if(document.location.toString()。indexOf('?')!== -1){
var query = document.location
.toString()
/ /获取查询字符串
.replace(/^.*?\?/,'')
//并删除任何现有的哈希字符串(谢谢,@vrijdenker)
.replace( /#.*$/,'')
.split('&'); (var i = 0,l = query.length; i< l; i ++){
var aux = decodeURIComponent(query [i])。
$ _GET [aux [0]] = aux [1];
//获取'index'查询参数
alert($ _ GET ['index']);
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 });
}
解决方案
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']);
这篇关于如何在javascript中获取GET变量的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文