2013-04-16 54 views
2

我讀過這一點 - Preselecting ajax-enabled tab in jquery UI tabs 並試圖API文檔...jQuery UI的,如何預先選擇標籤

這裏是最基本的代碼... http://jsfiddle.net/Xa2ur/

我想成爲能夠指定哪個選項卡被選中,但我可以找到的語法不起作用。

我最終會傳遞一個變量,但如果我無法獲得硬代碼,那麼採取額外步驟有什麼好處。

任何幫助 - 和「爲什麼」我做的沒有工作是非常感謝。

代碼

$(function() { 
    $("#tabs").tabs({ 
     beforeLoad: function(event, ui) { 
      ui.jqXHR.error(function() { 
       ui.panel.html("Couldn't load this tab. We'll try to fix this as soon as possible."); 
      }); 
     } 
    }); 
}); 

- 一些其他的代碼 -

<div id="tabs" > 
     <ul> 
      <li class="firsttab" ><a href="#tabs-1" >Wedding</a></li> 
      <li class="" ><a href="#tabs-2" >Gig Feb 2013</a></li> 
      <li class=""><a href="#tabs-3" >Homecoming</a></li> 
     </ul> 
     <div id="tabs-1" > 
      <p>Description: Wedding Info</p> 
      <p>photos</p> 
     </div> 
     <div id="tabs-2" > 
      <p>Description: A gig @ TT the Bears</p> 
      <p>blog</p> 
     </div> 
     <div id="tabs-3" > 
      Stuff 
     </div> 
    </div> 
    <script> 
     $("#tabs").tabs("option", "active", 2); 
     // i HAVE also tried - $('#tabs').tabs({ selected: "2" }); 
    </script> 

回答

4
$(function() { 
    $("#tabs").tabs({ 
     beforeLoad: function(event, ui) { 
      ui.jqXHR.error(function() { 
       ui.panel.html("Couldn't load this tab. We'll try to fix this as soon as possible."); 
      }); 
     }, 
     active:2 
    }); 
}); 
+0

THX - 我可以發誓,我試過,太...但這個工程。 非常感謝 – jpmyob

相關問題