简体   繁体   English

从锚链接直接链接到选项卡

[英]Link directly to tab from anchor link

I am trying to directly linking from anchor link like Go back to 3 tab And i can't make it working. 我正在尝试直接从锚定链接(如返回3选项卡)进行链接,但我无法使其正常工作。 It's working perfectly from the menu but when i am trying to linking from the tab5 to tab3 is not working with anchor. 它从菜单中可以正常工作,但是当我尝试从tab5链接到tab3时,无法使用锚点。

Here is the JS i am using. 这是我正在使用的JS。

<script type="text/javascript">




jQuery(document).ready(function() {
    jQuery('.tabs .tab-links a').on('click', function(e)  {
        var currentAttrValue = jQuery(this).attr('href');

        // Show/Hide Tabs
        jQuery('.tabs ' + currentAttrValue).show().siblings().hide();



        // Change/remove current tab to active
        jQuery(this).parent('li').addClass('active').siblings().removeClass('active');

        e.preventDefault();
    });





});

</script>

Is something wrong on my code or missing? 我的代码有问题还是遗漏了?

If i correctly understood you want to change tab programmatically, if so you can use $('.tabs').tabs('option', 'active', tab_index); 如果我正确理解了您想以编程方式更改选项卡的情况,则可以使用$('.tabs').tabs('option', 'active', tab_index); , check example bellow. ,请查看下面的示例。

Hope this helps. 希望这可以帮助。


 $(function() { $('.tabs').tabs(); $("#go_to_tab_3").click(function() { $('.tabs').tabs('option', 'active', 2); //index 2 mean tab 3 }); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script> <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/themes/base/jquery-ui.css" rel="stylesheet"/> <div class="tabs"> <ul> <li><a href="#tabs-1">Tab 1 </a></li> <li><a href="#tabs-2">Tab 2</a></li> <li><a href="#tabs-3">Tab 3</a></li> </ul> <div id="tabs-1"> <p>tab 1 content.</p> </div> <div id="tabs-2"> <p>tab 2 content.</p> </div> <div id="tabs-3"> <p>tab 3 content.</p> </div> </div> <br> <button id='go_to_tab_3' type='button'>Go to tab 3</button> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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