1

I have created a jquery ui tab and what I would like to do is when the page containing the jquery ui tab loads, specific tab will open depends on the previous page. So far, I have down the following:

PHP:

  1. obtain the previous page by using $_SERVER['HTTP_REFERER'];
  2. determine which tab to open by using a "if" statement (assigning a tab_index variable);
  3. assign "tab_index" to a hidden input value.

Javascript:

  1. pick up the hidden input value and assign it to a js variable;
  2. ??

Then I am not too sure how to do this make it work in $('#tabs').tabs({.... statement. Any idea of how to resolve this will be much appreciated. Many thanks.

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?...
});
});
4

1 回答 1

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?...
});
于 2013-05-02T17:03:12.177 回答