2013-05-02 41 views
1

我已經創建了一個jquery UI選項卡,我想要做的是當頁面包含jquery UI選項卡加載時,具體選項卡將打開取決於前一頁。到目前爲止,我倒有以下幾點:打開特定的jquery UI選項卡基於前一頁是

PHP:

  1. 使用$ _SERVER獲得前一頁[ 'HTTP_REFERER'];
  2. 通過使用「if」語句(分配tab_index變量)確定要打開哪個選項卡;
  3. 將「tab_index」賦值爲隱藏的輸入值。

使用Javascript:

  1. 拿起隱藏的輸入值,並將其分配到一個js變量;
  2. ??

然後我不太確定如何做到這一點使它在$('#tabs')。tabs({....語句。如何解決這個問題的任何想法將不勝感激。謝謝。

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

3. [PROFIT!](http://stackoverflow.com/questions/16343646/open-specific-jquery-ui-tab-based-on-which-the-previous-page-is) – 2013-05-02 17:04:14

回答

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

非常感謝弗雷迪,今天晚些時候我有機會試試。 – Wil 2013-05-03 01:16:44

+0

嗨弗雷迪,插入建議的腳本後,不管我點擊哪個標籤,它直接切換回標籤0.任何想法如何解決這個問題?謝謝 – Wil 2013-05-03 13:50:40

相關問題