简体   繁体   中英

Button won't change tab in JQuery UI Tabs

I have a web page that has JQuery tabs with iFrames loaded in the 2nd through 4th tab. My problem is in a button I've added to the first tab. I want that button, when pressed, to change to the next tab.

EDIT 1: Here is a fiddler that shows my problem. http://jsfiddle.net/lochalan/AXa9J/

Webpage:

<!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;
    }

});

Why won't my button change the tab?

Use active option to select current or change tab

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

There's a few things wrong here, more than I'm willing to cover on a forum unfortunately.

If you're going to use jQueryUI then I suggest you go use ThemeRoller . Do a UI theme and use the CSS it generates for you. The classes are named very intuitively and it will help you identify what your functions are working on. Use Firefox with Firebug plugin so you can debug. You're on the right track but you're still cloudy on some core concepts.

jQuery Tabs API
jQueryUI ThemeRoller

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM