【问题标题】:retrieve window.location.hash url in php在 php 中检索 window.location.hash url
【发布时间】:2009-05-24 17:52:46
【问题描述】:

我在这里http://www.imashdigital.com/#2使用jquery选项卡式界面,并希望在php中返回选项卡号。

理想情况下,我想运行一个 javascript 函数(在计时器上),该函数会使用当前选项卡不断更新全局 php 变量

基于这个 php 值,从 1 到 4,然后我将加载不同的侧边栏。

由于我是新手,我将不胜感激任何帮助和一些代码示例。

亲切的问候

乔纳森

【问题讨论】:

  • 为什么不选择标签时根据标签更改侧边栏?

标签: php javascript jquery


【解决方案1】:

哈希之后的 URI 部分永远不会发送到服务器。 PHP 无法访问它。请改用查询字符串参数 ($_GET)。或者使用客户端脚本 (javascript)。

【讨论】:

  • 嗯,不确定你是不是对我投了反对票的人,但是使用我的方法哈希通过就好了
  • 客户端脚本实际上是 Paolo 示例中所建议的,不是吗?
  • PepperBob:我的意思是单独的客户端脚本。 Paolo 的示例将状态存储在服务器端。我想真正的问题是为什么 Jonathan 想知道 PHP 中的选定选项卡?
【解决方案2】:

我建议您不要运行计时器,而是将 $.post 附加到事件“标签激活”。这将实时应用任何选项卡更改,并且不会触发不必要的请求。

【讨论】:

    【解决方案3】:

    我在最近的几个项目中使用了选项卡式面板,我使用的解决方案如下:

    HTML

    <ul class="tabs">
      <li><a href="#en_en">English</a></li>
      <li><a href="#fr_fr">Français</a></li>
    </ul>
    <div class="panel" id="en_en"><!-- Content --></div>
    <div class="panel" id="fr_fr"><!-- Content --></div>
    

    jQuery

    // the currently selected tab, or a default tab (don't forget to prepend the #)
    var tab = location.hash || '#en_en';
    
    // register a click handler on all the tabs
    $('ul.tabs a').click(function(event){
        event.preventDefault(); // prevents the browser from scrolling to the anchor
    
        // hide all panels, then use the link's href attribute to find 
        // the matching panel, and make it visible
        // you can, of course, use whatever animation you like
        $('div.panel').hide().filter(  $(this).attr('href')  ).show();
    
    ).filter('[href*='+tab+']').click();
    // above: in case of refreshing/bookmarking: find the tab link that contains
    // the current location.hash, and fire its click handler
    

    它运行良好,因为服务器端代码不需要知道选择了哪个选项卡,但它还支持刷新或为特定选项卡添加书签,而无需用户再次选择选项卡。

    【讨论】:

      猜你喜欢
      • 2013-03-02
      • 1970-01-01
      • 2017-10-30
      • 2010-12-29
      • 1970-01-01
      • 1970-01-01
      • 2011-12-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多