2013-09-29 124 views
0

我正在使用jQuery UI選項卡,我想更改按鈕單擊上的選項卡。我該怎麼做?jQuery選項卡手動選擇

這是我的標記,它描述了選項卡的html和jQuery選項卡的javascript代碼。

<ul class="tabs"> 
    <li><a href="#">tab 1</a></li> 
    <li><a href="#">tab 2</a></li> 
    <li><a href="#">tab 3</a></li> 
</ul> 

<div class="tab-content"> 
    <div>Tab 1</div> 
    <div>Tab 2</div> 
    <div>Tab 3</div> 
</div> 

<input type="button" onclick="changetab(2)">Go to 2nd Tab</input> 

<script type="text/javascript"> 
    (function() { 

    $(".tabs-container").each(function() { 
     var $history = $(this).attr('data-history'); 
     if ($history != undefined && $history == 'true') { 
      $history = true; 
     } else { 
      $history = false; 
     } 
     var $initialIndex = $(this).attr('data-initialIndex'); 
     if ($initialIndex == undefined) { 
      $initialIndex = 0; 
     } 
     $("ul.tabs", this).tabs("div.tab-content > div", { tabs: 'a', effect: 'fade', fadeOutSpeed: -200, history: $history, initialIndex: $initialIndex }); 
    }); 

    })(); 

    function changetab(index){ 
     // WHAT TO DO HERE!!! 
    } 
</script> 

回答