2013-05-17 28 views
1

的標籤窗格我嘗試設置活躍的一類表的引導?Set類活躍在tabbable引導

<div class="tabbable tabs-left"> 
    <ul class="nav nav-tabs"> 
     <?php 
      foreach ($this->aliasRead as $key => $value): 
       echo '<li class="active"><a href="#'.$value[0].'" data-toggle="tab">'.$value[0].' 
        <button class="btn btn-danger" ><i class="icon-trash icon-white"></i></button></a> 
        </li> 
        '; 
      endforeach; 
     ?> 
    </ul> 

    <div class="tab-content"> 

     <?php foreach ($this->aliasRead as $key => $value): 
      echo '<div class="tab-pane active" id="'.$value[0].'">'; 
     ?> 

      <H4>Alias redirigé vers l'adresse : 
       <button href="#modifalias" role="link" data-toggle="modal" class="btn btn-primary"><i class="icon-plus icon-white"></i></button> 
      </H4> 

      <table class="table table-striped"> 
       <tbody> 
        <?php foreach ($value as $key => $v): 
         if($key > 0) 
          echo '<tr> 
           <td>'.$v.'</td> 
           <td> 
           <button class="btn btn"><i class="icon-trash"></i></button> 
           </td> 
           </tr>'; 
         endforeach; 
        ?> 
       </tbody> 
      </table> 
     <?php endforeach; ?> 
    </div>    
</div> 

在本例中,所有標籤窗格是活動的,所有是活動的,我只是想設置類主動當我在點擊:

編輯

我試了一下,它是爲李的作品,當我點擊,但我嘗試設置活動的類是活躍的類標籤頁當我clik上一個李

我嘗試,不起作用。

<script type="text/javascript"> 
$(function(){ 
    $('.nav-tabs li').on('click', function(event) { 
     $('.nav-tabs li').removeClass('active'); // remove active class from tabs 
     $(this).addClass('active'); // add active class to clicked tab 
    }); 
    $('.nav-tabs li').on('click', function(event) { 
     $('.tab-content div').removeClass('active'); 
     $('.tab-content div').addClass('active'); 
    }); 

}); 

</script> 

的probleme是LIGNE:

$('.tab-content div').addClass('active'); 

如何選擇正確的一個tabpanel對應於李?

回答

2

雖然您使用PHP構建頁面,它看起來像標籤更改通過JavaScript處理(除非您提供有關標籤的變化是如何處理的進一步代碼)

假設是正確的,你需要使用JavaScript來處理活動類的設置,而不是PHP。

例如

$('.nav-tabs li').on('click', function(event) { 
    $('.nav-tabs li').removeClass('active'); // remove active class from tabs 
    $(this).addClass('active'); // add active class to clicked tab 
}); 

我依據此對一些大的假設,雖然,即你正在處理的JS標籤的變化不是PHP

編輯:

試圖增加這您的標籤頁輸出

<li class="active"><a href="#'.$value[0].'" data-toggle="tab" data-id="'.$value[0].'"> 

然後,在JavaScript替換一下我這個

$('.nav-tabs li').on('click', function(event) { 
    $('.nav-tabs li').removeClass('active'); // remove active class from tabs 
    $(this).addClass('active'); // add active class to clicked tab 
    $('.tab-content div').hide(); // hide all tab content 
    $('#' + $(this).data('id')).show(); // show the tab content with matching id 
}); 

先前建議您也將隱藏在頁面加載的所有標籤內容塊,除了你的inital標籤

+0

編輯我的帖子,你可以看編輯? @fullybaked – mpgn

+0

@MartialE嘗試閱讀Bootstrap http://twitter.github.io/bootstrap/javascript.html#tabs上的Javascript選項卡文檔,它解釋瞭如何在點擊選項卡鏈接 – fullybaked

+0

已嘗試使您的內容正常工作,對我來說沒有結果。他們顯示基本的例子,但在我看來,這是更具體的我想。 – mpgn

0

爲什麼鴕鳥政策設置

$ I = 1,

<?php 
     foreach ($this->aliasRead as $key => $value): 

        echo '<li <?if($i ==1){echo 'class="active"';}?>><a href="#'.$value[0].'" data-toggle="tab">'.$value[0].' 
           <button class="btn btn-danger" ><i class="icon-trash icon-white"></i></button></a> 
          </li> 
         '; $i++ 
     endforeach; 
    ?> 

這解決了全部重新活躍的問題。我不明白第二,但我會檢查我與標籤工作的項目,也許我會編輯這篇文章。

@fullybaked發佈正確的補充,我想現在研究。

1

如果您使用引導,不應該的JavaScript這是簡單的:

$('.nav-tabs a').click(function (e) { 
    e.preventDefault(); 
    $(this).tab('show'); 
});