du5910 2013-06-05 15:05
浏览 37

传递GET变量并转到jQuery选项卡

I have a jQuery tabs set up on a page on my website. I want to reference one of the tabs using a URL which I can do using:

http://url.com/tabs#my-tab 

However, I also want to pass a few php variables to this page THROUGH the url as well. I have tried with minimal success by doing this:

http://url.com/tabs?var1=foo&var2=bar#my-tab

however this only seems to pass the first variable, the second one is ignored (it does go to the tab). I cannot find a way to send several variables and go to the tab. Can someone please help Thanks

  • 写回答

1条回答 默认 最新

  • doqs8936 2013-08-08 13:14
    关注

    Without seeing your code, I would guess that whatever method you're using to parse those GET variables isn't working. Try this method instead. First, do the following:

    // Store the query string variables into an object.
    window.getVars = {};
    (function () {
        var match,
            pl     = /\+/g,  // Regex for replacing addition symbol with a space
            search = /([^&=]+)=?([^&]*)/g,
            decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); },
            query  = window.location.search.substring(1);
    
        while (match = search.exec(query))
           window.getVars[decode(match[1])] = decode(match[2]);
    })();
    

    Then, you should be able to access any of your GET variables as window.getVars.var1, window.getVars.var2, etc.

    评论

报告相同问题?

悬赏问题

  • ¥15 对于这个问题的代码运行
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败