【问题标题】:open a bootstrap modal with a specific HIDDEN TAB(without nav-tabs ) by jquery通过 jquery 打开具有特定隐藏选项卡(没有导航选项卡)的引导模式
【发布时间】:2019-06-29 08:59:17
【问题描述】:

此模式框没有可见的选项卡。我只是使用 href 属性 导航到其他页面。

<div id="bootmodal" class="modal fade" tabindex="-1" data-width="370" data-backdrop="static" data-keyboard="false" style="display: none;">
    <div class="tab-content">

    <!--
        NOTE: i'll not use nav-tab
        ===========================
        <ul class="nav nav-tabs col-md-3 custom-bullet">
            <li class="active"><a data-toggle="tab" href="#login_tab">Login</a></li>
            <li><a data-toggle="tab" href="#lostpass_tab">Lost Your Password?</a></li>
        </ul>
    -->

        <div class="tab-pane active fade in" id="login_tab">
            <form id="login" action="login" method="post">
                <div class="modal-header">
                </div>
                <div class="modal-body">
                </div>
                <div class="modal-footer">
                    <a href="#lostpass_tab" data-toggle="tab"><span class="label label-info pull-left"><?php _e('Lost your password?','woocomputers'); ?></span></a>
                    <?php if (get_option( 'users_can_register' ) != true): ?>
                        <a href="#register_tab" data-toggle="tab"><span class="label label-danger pull-right"><?php _e('Registration is disable rightn now!','woocomputers'); ?></span></a>
                    <?php else: ?>
                    <a href="#register_tab" data-toggle="tab"><span class="label label-danger pull-right"><?php _e('Create a New Account.','woocomputers'); ?></span></a>
                    <?php endif; ?>
                </div>
            </form>
        </div>

        <?php if (get_option( 'users_can_register' ) == true): ?>
            <div class="tab-pane fade in" id="register_tab">
            </div>
        <?php endif; ?>

        <div class="tab-pane fade in" id="lostpass_tab">
        </div>

    </div>
</div>

我想通过使用打开特定的隐藏标签

<button type="button" id="wp-ajax-logout" class="btn"  data-toggle="modal" data-target="#bootmodal">Login</button>
<button type="button" id="wp-ajax-lost-pass" class="btn"  data-toggle="modal" data-target="#bootmodal">Lost your password</button>

或通过标签

<a href="#login_tab" class="btn" data-toggle="modal" data-target="#bootmodal" >Register</a>
<a href="#lostpass_tab" class="btn" data-toggle="modal" data-target="#bootmodal" >Register</a>

有没有办法使用 jquery 打开特定的隐藏标签?

编辑:

我想通过短代码功能使用页面模板中的触发器&lt;button&gt;Register&lt;/button&gt;&lt;a href="#login_tab"&gt;Login&lt;/a&gt;

我在网站周围找到了一些代码。他们使用js。

$("#bootmodal").on('shown.bs.modal', function(e) {
    var tab = e.relatedTarget.hash;
    $('.nav-tabs a[href="'+tab+'"]').tab('show')
})

在这里他们使用.nav-tabs,但我不想要。没有这个问题,一切都很好。

【问题讨论】:

    标签: ajax jquery twitter-bootstrap


    【解决方案1】:

    是的,您可以使用 jquery 打开特定的隐藏选项卡。我已经创建了演示,您可以参考下面的 sn-p 代码。

    HTML

    <ul class="tab-controllers">
          <li class="active"><a id="login_tab_btn" class="btn active" data-toggle="modal" data-target="#bootmodal"  >Login</a></li>
          <li><a id="lostpass_tab_btn" class="btn" data-toggle="modal" data-target="#bootmodal" >Lost Your Password?</a></li>
          <li><a id="register_tab_btn" class="btn" data-toggle="modal" data-target="#bootmodal">Register</a></li>
    </ul>
    
    
    <div id="bootmodal" class="modal fade" tabindex="-1" data-width="370" data-backdrop="static" data-keyboard="false" style="display: none;">
        <div class="tab-content">
    
    
            <div class="tab-pane active" id="login_tab">
                <form id="login" action="login" method="post">
                    <div class="modal-header"> <h2>Login tab Content</h2>
                    </div>
                    <div class="modal-body">
                    </div>
                    <div class="modal-footer">
                     <a href="#lostpass_tab_btn"><span class="label label-info pull-left"><?php _e('Lost your password?','woocomputers'); ?></span></a>
                    <?php if (get_option( 'users_can_register' ) != true): ?>
                        <a href="#register_tab_btn"><span class="label label-danger pull-right"><?php _e('Registration is disable rightn now!','woocomputers'); ?></span></a>
                    <?php else: ?>
                    <a href="#register_tab_btn"><span class="label label-danger pull-right"><?php _e('Create a New Account.','woocomputers'); ?></span></a>
                    <?php endif; ?>                          
                    </div>
                </form>
            </div>
    
            <?php if (get_option( 'users_can_register' ) == true): ?>
                <div class="tab-pane" id="register_tab">
                   <div class="modal-header"> <h2>register tab Content</h2>
                    </div>
                    <div class="modal-body">
    
                         </div>
                        <div class="modal-footer">                    
                    </div>
                </div>
            <?php endif; ?>
    
            <div class="tab-pane" id="lostpass_tab">
              <div class="modal-header"><h2>Lost Password tab Content</h2>
                    </div>
                    <div class="modal-body">
                    </div>
                    <div class="modal-footer">                    
                    </div>
            </div>
    
        </div>
    </div>
    

    JS

    jQuery(document).ready(function($) {
    
    jQuery('#login_tab').show();
    jQuery('#register_tab').hide();
    jQuery('#lostpass_tab').hide();
    
    jQuery(document).on('click', '#login_tab_btn', function() {
        jQuery(".tab-controllers li").removeClass("active");
        jQuery(".tab-controllers li a").removeClass("active");
        jQuery(this).addClass("active");
        jQuery(this).parent().addClass("active");
        jQuery('#register_tab').hide();
        jQuery('#lostpass_tab').hide();
        jQuery('#login_tab').show();
    });
     jQuery(document).on('click', '#lostpass_tab_btn', function() {
        jQuery(".tab-controllers li").removeClass("active");
        jQuery(".tab-controllers li a").removeClass("active");
        jQuery(this).addClass("active");
        jQuery(this).parent().addClass("active");
        jQuery('#login_tab').hide();
        jQuery('#register_tab').hide();
        jQuery('#lostpass_tab').show();
    });
     jQuery(document).on('click', '#register_tab_btn', function() {
        jQuery(".tab-controllers li").removeClass("active");
        jQuery(".tab-controllers li a").removeClass("active");
        jQuery(this).addClass("active");
        jQuery(this).parent().addClass("active");
        jQuery('#login_tab').hide();
        jQuery('#lostpass_tab').hide();
        jQuery('#register_tab').show();
    });
    });
    

    如果这对你有帮助,请告诉我!

    【讨论】:

    • 你使用tab-controllers 类,但我不想在模态中使用它。触发器将在我的页面模板文件中。我从几个网站上找到了一些代码。我会再次编辑我的问题。请尝试给我正确的答案。
    • 你也可以在模型之外使用“tab-controller”div。我已经更新了我的答案。单击特定链接时,它将显示该容器。如果您有任何疑问,请告诉我。
    • @Chetan Vaghela,非常感谢,一切正常。但现在的问题是,在我使用您的 jquery 代码 (请参阅我的登录表单的 .modal-footer 类链接) 之后,我无法使用 .modal-footer 类链接。有没有办法使用链接将一个表格转到另一个表格(登录注册或丢失密码表格)
    • @Chetan Vaghela,我在等你的答复。请有人帮助我。
    • 抱歉回复晚了。我已经更新了我的答案并在 .modal-footer 类中添加了链接。请现在检查。让我知道这是否适合您。
    猜你喜欢
    • 1970-01-01
    • 2020-03-14
    • 2016-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-16
    • 2013-01-27
    • 2021-02-10
    相关资源
    最近更新 更多