2013-02-22 163 views
0

我有一個網頁,其中有第二到第四個選項卡加載了iFrames的JQuery選項卡。我的問題是我已經添加到第一個標籤的按鈕。我想要那個按鈕在按下時切換到下一個選項卡。按鈕不會更改JQuery UI選項卡中的選項卡

編輯1:這是一個提示我的問題的提琴手。 http://jsfiddle.net/lochalan/AXa9J/

網頁:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head> 
<title>Student Application</title> 
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.1/themes/base/jquery-ui.css" /> 
<script src="http://code.jquery.com/jquery-1.9.1.js"></script> 
<script src="http://code.jquery.com/ui/1.10.1/jquery-ui.js"></script> 
<script src="/user/tabs.js" type="text/javascript"></script> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
<style type="text/css"> 
      html { 
       font-size:10px; 
      } 

      .iframetab { 
       width:100%; 
       height:auto; 
       border:0px; 
       margin:0px; 
       position:relative; 
       top:-13px; 
      } 

      .ui-tabs-panel { 
       padding:5px !important; 
      } 

      .openout { 
       float:right; 
       position:relative; 
       top:-28px; 
       left:-5px; 
      } 
     </style> 
</head> 

<body> 
    <table width="100%" cellpadding="0" cellspacing="0" border="0"> 
    <tr><td> 
    <img src="img/logo960x100moodle.png" width="960" height="92" alt=""><br> 
    </td></tr> 
    </table> 

<div id="tabs"> 
    <ul> 
    <li><a href="#tabs-1">Instructions</a></li> 
    <li><a class="tabref" href="#tabs-2" rel="/user/application-tab.php">Student Information</a></li> 
    <li><a class="tabref" href="#tabs-3" rel="/user/emergency-tab.php">Emergency Contact</a></li> 
    <li><a class="tabref" href="#tabs-4" rel="/user/healthform-tab.php">Health Form</a></li> 
    </ul> 
    <div id="tabs-1" class="tabMain"> 
    <h2>Welcome to QSI Shekou!</h2> 
     <p>This application is designed to give the school all the information needed to make an informed decision as to whether QSI is the best school for your child. We believe all children can be successful and we are proud that you have choosen QSI Shekou as that place. In the next few minutes, you will be presented with 3 seperate application forms. The first application gathers the needed biographical information about your child. The second form provides the school with emergency contact information and instructions in the event the school needs to contact someone on your child's behalf. The third form is our health form. This provides the school with information about your child's health in order to help us make QSI Shekou a fun and safe place to learn and grow.</p> 
     <p><strong>Remember to give the following documents to the admissions department:</strong></p> 
      <ul> 
       <li>Immunization records (copy)</li> 
       <li>Health/Emergency Form (Found on our Website)</li> 
       <li>Previous School Records (copy)</li> 
       <li>Student's Passport (copy)</li> 
       <li>Student's Visa (copy)</li> 
       <li>Mother's Passport (copy)</li> 
       <li>Mother's Visa (copy)</li> 
       <li>Father's Passport (copy)</li> 
       <li>Father's Visa (copy)</li> 
       <li>3 Student Passport Photos</li> 
      </ul>  
     <button class="nexttab" href="#"><strong>Let's get started!</strong></button> 
    </div> 
    <div id="tabs-2"> 
    </div> 
    <div id="tabs-3"> 
    </div> 
    <div id="tabs-4"> 
    </div> 
</div> 


</body> 
</html> 

的JavaScript/jQueryUI的:

$(document).ready(function() { 
    var $tabs = $('#tabs').tabs(); 

    $(".nexttab").click(function() { 
    var selected = $("#tabs").tabs("option", "selected"); 
    $("#tabs").tabs("option", "selected", selected + 1); 
    }); 

//get selected tab 
    function getSelectedTabIndex() { 
     return $tabs.tabs('option', 'selected'); 
    } 

//get tab contents 
    beginTab = $("#tabs ul li:eq(" + getSelectedTabIndex() + ")").find("a"); 
    loadTabFrame($(beginTab).attr("href"),$(beginTab).attr("rel")); 

    $("a.tabref").click(function() { 
     loadTabFrame($(this).attr("href"),$(this).attr("rel")); 
    }); 

//tab switching function 
    function loadTabFrame(tab, url) { 
     if ($(tab).find("iframe").length == 0) { 
      var html = []; 
      html.push('<div class="tabIframeWrapper">'); 
      html.push('<div class="openout"><a href="' + url + '"><img src="data/world.png" border="0" alt="Open" title="Remove iFrame" /></a></div><iframe class="iframetab" src="' + url + '">Load Failed?</iframe>'); 
      html.push('</div>'); 
      $(tab).append(html.join("")); 
      $(tab).find("iframe").height($(window).height()-80); 
     } 
    return false; 
    } 

}); 

爲什麼我的按鈕更改選項卡?

回答

1

使用active選項選擇當前或更改標籤

var selected = $("#tabs").tabs("option", "active"); 
$("#tabs").tabs("option", "active", selected + 1); 
+0

對不起,沒有工作。我用我的問題創建了一個小提琴手。 http://jsfiddle.net/lochalan/AXa9J/ – Nathan 2013-02-22 02:04:41

+0

,因爲你在'nextTab'函數中附加了單擊事件,它永遠不會被調用http://jsfiddle.net/mZzPN/ – dmk 2013-02-22 02:09:16

+0

是的!你是對的。謝謝! – Nathan 2013-02-22 02:22:31

0

有幾件事錯在這裏,比我願意不幸覆蓋在論壇上。

如果你打算使用jQueryUI,那麼我建議你去使用ThemeRoller。做一個UI主題,並使用它爲你生成的CSS。這些類非常直觀地命名,它將幫助您識別您的功能正在處理的內容。使用Firefox和Firebug插件,以便調試。你在正確的軌道上,但你仍然在一些核心概念上陰霾。

jQuery Tabs API
jQueryUI ThemeRoller

+0

我接受了你的建議,並從ThemeRoller下載了一個主題,並清理了我的代碼。感謝您的建議! – Nathan 2013-02-22 03:08:02

+0

太棒了!很多例子都使用了整合者類名。一旦你已經充分了解它們並在例子中認識它們,你的學習曲線就開始變得直白了。祝你好運! – 2013-02-22 04:16:28

相關問題