2009-12-27 209 views
0

我想在選擇帶日期選擇器的日期後返回到上次打開的選項卡。我嘗試通過獲取選定的選項卡來做到這一點。這適用於靜態選項卡,但不適用於ajax調用,因爲該選項卡會得到不同的索引號。 我該如何做到最好?jquery選項卡和日期選擇器

這是我的代碼:

 <script type="text/javascript" src="js/jquery-1.3.2.min.js"></script> 
    <script type="text/javascript" src="js/jquery-ui-1.7.2.custom.min.js"></script> 
    <script type="text/javascript" src="js/sitewide.js"></script> 
    <script type="text/javascript"> 
     <!-- 
     $(function(){ 

      // Tabs 
      $('#tabs').tabs({ 

       ajaxOptions: { cache: false } 
      }); 

      // Datepicker 
      $('.datepicker').datepicker({ 
       onSelect: showDate 
      }); 

     }); 


     function showDate(date) { 
      var $tabs = $('#tabs').tabs(); 
      var selected = $tabs.tabs('option', 'selected'); // => 0 
      location.href = "./index.php?datum="+date+"#tabs-"+selected; 
     } 

,並在頁面的主體:

<div id="tabs"> 
<ul> 
<li><a href="#tabs-1"><span><img src="img/home-klein.png" border="0" height="15"></span></a></li> 
      <li><a href="./includes/c-boten.php?datum=<?php echo $start ;?>"><span>C-boten</span></a></li> 
      <li><a href="./includes/gladde-boten.php?datum=<?php echo $start ;?>"><span>Gladde boten</span></a></li> 
      <li><a href="./includes/jeugd-boten.php?datum=<?php echo $start ;?>"><span>Jeugdboten</span></a></li> 
      <li><a href="./includes/wherries.php?datum=<?php echo $start ;?>" id="tabs4"><span>Wherries</span></a></li> 
      <li><a href="./includes/stats.php"><span>Kilometerstanden</span></a></li> 
      <li><a href="#tabs-6"><span>Weer & Wind</span></a></li> 
      <li><a href="./includes/schadekaarten.php"><span>Schadekaarten</span></a></li> 
      <?php 
      if($_SESSION["anonymous"] != "1"){ 
      echo "<li><a href=\"#tabs-8\"><span>Uitloggen</span></a></li>"; 
      } 
      ?> 

     </ul> 

     <div id="tabs-1"> 
     div 1 text 
     </div> 

有什麼建議?

回答

0

嘗試處理標籤select事件和可變跟蹤ui.index

例如:

var selectedTab = 0; 
$('#tabs').tabs({ 
    ajaxOptions: { cache: false }, 
    select: function(event, ui) { selectedTab = ui.index; } 
});