根据上一页打开特定的jquery ui选项卡

时间:2013-05-02 16:57:32

标签: php javascript

我创建了一个jquery ui选项卡,我想要做的是当包含jquery ui选项卡的页面加载时,将打开特定选项卡取决于上一页。到目前为止,我有以下几点:

PHP:

  1. 使用$ _SERVER ['HTTP_REFERER'];
  2. 获取上一页
  3. 使用“if”语句确定要打开的选项卡(指定tab_index变量);
  4. 将“tab_index”指定给隐藏的输入值。
  5. 使用Javascript:

    1. 选取隐藏的输入值并将其分配给js变量;
    2. ...
    3. 然后我不太确定怎么做才能让它在$('#tabs')中工作。制表符({....声明。如何解决这个问题的任何想法将非常感谢。非常感谢。< / p>

      PHP:
      $string = $_SERVER['HTTP_REFERER'];
      $string = substr($string, -(strlen($string)-strrpos($string, '/')-1), strlen($string)-strrpos($string, '/'));
      if ($string == "specific_page.php") {
          $tab_index = 2;
      } else {
          $tab_index = 0;
      }
      
      HTML:
      ...
      <input id="hidden_input" type="hidden" value="<?php echo $tab_index; ?>" />
      
      JS:
      $(document).ready(function() {
      var tab_index = $('#hidden_input').attr('value')
      $('#tabs').tabs({ cache:false,
          ajaxOptions: {
              error: function(xhr, status, index, anchor) {
                  $(anchor.hash).html("Couldn't load this tab. We'll try to fix this as soon as possible.");
              }
          },
          ...something here for tab selection?...
      });
      });
      

1 个答案:

答案 0 :(得分:0)

您可以使用

定义活动标签
$(".selector" ).tabs({active: 2 });

意思是,如果我正确理解你的tab_index,那么你的代码就是。

$('#tabs').tabs({
cache: false,
active: tab_index,
ajaxOptions: {
    error: function(xhr, status, index, anchor) {
        $(anchor.hash).html("Couldn't load this tab. We'll try to fix this as soon as possible.");
    }
},
...something here for tab selection?...
});