Next-Prev functionality for the jquery tabs

后端 未结 3 827
傲寒
傲寒 2021-01-24 03:39

I need Next, Previous functionality for the jquery tabs on clicking on the Next and Prev html buttons. I am using jquery.1.9.1.js and jquery-ui-1.10.2.custom.

相关标签:
3条回答
  • 2021-01-24 04:21
    <script src="jquery-1.5.1.min.js" type="text/javascript"></script>
    <script src="jquery-ui.js" type="text/javascript"></script>
    <link href="jquery-ui.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
        $(function () {
            $("#ui-tabs").tabs();
        });
        function GetSelectedTabIndex() {
            var $tabs = $('#ui-tabs').tabs();
            var selected = $tabs.tabs('option', 'selected');
            return selected;
        }
    
        function ShowTabs(stepNum) {
            var num = parseInt(stepNum);
            $('#ui-tabs').tabs('select', parseInt(GetSelectedTabIndex()) + num);
        }
    </script>
    
    
    
    <div id="ui-tabs">
        <ul>
            <li><a href="#tabs-1">Nunc tincidunt</a></li>
            <li><a href="#tabs-2">Proin dolor</a></li>
            <li><a href="#tabs-3">Aenean lacinia</a></li>
        </ul>
        <div id="tabs-1">
            Tab1 content
        </div>
        <div id="tabs-2" >
            Tab2 content
        </div>
        <div id="tabs-3">
            Tab3 content
        </div>
    </div>
    
    0 讨论(0)
  • 2021-01-24 04:36

    This works for me:

    $( "#ui-tabs" ).tabs();
    
     function GetSelectedTabIndex() {
            return $('#ui-tabs').tabs('option', 'selected');
     }
    
    function ShowTabs(stepNum) {
        var num = parseInt(stepNum);
        $('#ui-tabs').tabs('option', 'active', parseInt(GetSelectedTabIndex()) + num);
    }
    

    It seems to me that there's no point in using the $tabs variable, as it's local to your GetSelectedTabIndex function, and it's only used once per function call...

    Demo: http://jsfiddle.net/darkajax/A8ejN/

    0 讨论(0)
  • 2021-01-24 04:42

    There is no select method for jQuery UI Tabs in this version. To get your functionality to work you need to change your code to

    var i=$('#ui-tabs').tabs( "option", "active"); //get selected tab index
    $('#ui-tabs').tabs( "option", "active", i+num ); // num is your tab choise (+1,-1)
    

    This is worked for me. Try this.

    0 讨论(0)
提交回复
热议问题