【问题标题】:jQuery and $_GETjQuery 和 $_GET
【发布时间】:2010-03-05 13:36:29
【问题描述】:

假设我有这个网址:www.example.com/test.php?page=4

如何使用 jQuery 检索 $_GET['page'] 的值? o_O

【问题讨论】:

  • 之前没见过-get标签。
  • 我不明白这个问题。 $_GET 是一个服务器端的概念。
  • 他正在尝试从 jQuery 访问 URL 参数
  • sshow,确实如此。这不可能吗?

标签: php jquery get


【解决方案1】:

【讨论】:

    【解决方案2】:

    如果你没有jQuery或者你不想使用插件,你可以使用netlobo.com的这段代码:

    function gup( name )
    {
      name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
      var regexS = "[\\?&]"+name+"=([^&#]*)";
      var regex = new RegExp( regexS );
      var results = regex.exec( window.location.href );
      if( results == null )
        return "";
      else
        return results[1];
    }
    

    然后按如下方式使用:

    var pageNumber = gup( 'page' );
    

    【讨论】:

      猜你喜欢
      • 2014-07-04
      • 1970-01-01
      • 2018-08-18
      • 1970-01-01
      • 1970-01-01
      • 2010-10-01
      • 2010-11-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多