javascript - 如何在javascript中获取GET变量的值?

标签 javascript get

<分区>

Possible Duplicate:
Get query string values in 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']);

关于javascript - 如何在javascript中获取GET变量的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12049620/

相关文章:

php - 循环遍历 URL 参数并添加到 mySQL

html - 使用 CodeIgniter 获取 URL 中的参数

javascript - 如何在 React Js 中为 react 表的 <tr> 添加类?

javascript - 厄运金字塔

javascript - HTML5/Javascript - 是否可以在浏览器中获取 Macbook 触控板上触摸事件的绝对坐标?

PHP $_GET ['action']

rest - Angular2 REST API

javascript - 提交后打开/关闭 Div 标签

javascript - jQuery $.parseJSON 数据到 HTML

ruby - Rspec Controller 中显示的#<RSpec::Core::ExampleGroup::Nested_1 的未定义方法 `get'