1

我使用了 JQuery UI 选项卡,并且我的选项卡工作正常。请看下面的代码。

<ul class="tabs">
    <li><a href="#tab1">Login</a></li>
    <li><a href="#tab2">Register User</a></li>
    <li><a href="#tab3">Forgot Password </a></li>


</ul>
<div class="tab_container">
    <div id="tab1" class="tab_content clearfix">
        <h2>Login</h2>
        <div class="login-form">
                <div class="username-bg"><input name="a" type="text" value="username" /><img src="images/user-icon.png" alt="" /></div>
                <div class="password-bg"><input name="a" type="password" value="password" /><img src="images/password-icon.png" alt="" /></div>
                <a href="#tab3" class="login-text">Lost Your Password ?</a>
                <a href="preprints.html" class="signup"></a>            
        </div>
    </div>
    <div id="tab2" class="tab_content ">
        <h2>Register User</h2>
        <div class="login-form">
                <div class="username-bg " ><input name="a" type="text" value="username" required  /><img src="images/user-icon.png" alt="" /></div>
                <div class="password-bg"><input name="a" type="password" value="password" /><img src="images/password-icon.png" alt="" /></div>             
                <a href="#tab3" class="login-text">Lost Your Password ?</a>
                <a href="preprints.html" class="save"></a>          
        </div>
    </div>
    <div id="tab3" class="tab_content">
        <h2>Forgot Password</h2>
        <div class="login-form">
                <div class="username-bg"><input name="a" type="text" value="new password" /><img src="images/password-icon.png" alt="" /></div>
                <div class="password-bg"><input name="a" type="text" value="confirm password" /><img src="images/password-icon.png" alt="" /></div>
                <a href="#tab3" class="login-text">Lost Your Password ?</a>
                <a href="preprints.html" class="save"></a>          
        </div>


    </div>

</div>

我使用的Jquery如下

<script type="text/javascript">

$(document).ready(function() {

    //Default Action
    $(".tab_content").hide(); //Hide all content
    $("ul.tabs li:first").addClass("active").show(); //Activate first tab
    $(".tab_content:first").show(); //Show first tab content

    //On Click Event
    $("ul.tabs li").click(function() {
        $("ul.tabs li").removeClass("active"); //Remove any "active" class
        $(this).addClass("active"); //Add "active" class to selected tab
        $(".tab_content").hide(); //Hide all tab content
        var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
        $(activeTab).fadeIn(); //Fade in the active content
        return false;
    });

});
</script>

现在我想要标签内的一个链接Lost Your Password ?链接到忘记密码标签的 tab3,但它不工作请帮忙。谢谢

4

1 回答 1

0

给选项卡内的链接一个新类(例如class="linktab")和一个数据属性(例如data-tab="3")并使用类似的东西

$('a.linktab').click(function() {
    $('.tabs').tabs('option', 'active', $(this).data('tab'));
    return false;
});
于 2013-08-30T08:03:02.263 回答