开发者

Tabs script from jscrollpane - making one of the tabs default

开发者 https://www.devze.com 2023-03-27 23:26 出处:网络
I\'m trying to implement tabs on a website i\'m working on but i\'m having trouble making the first tab default.

I'm trying to implement tabs on a website i'm working on but i'm having trouble making the first tab default.

I'm using the code from jscrollpane:

        <script type="text/javascript" id="sourcecode">
        $(function()
        {
            $('.menu').each(
                function()
                {
                    var currentTab, ul = $(this);
                    $(this).find('a').each(
                        function(i)
                        {
                            var a = $(this).bind(
                                'click',
                                function()
                                {
                                    if (currentTab) {
                                        ul.find('a.active').removeClass('active');
                                        $(currentTab).hide();
                                    }
                                    currentTab = $(this).addClass('active')
                                                    .attr('href');
                                    $(currentTab).show().jScrollPane();
                                    return false;
                                }
                            );
                            $(a.attr('href')).hide();
                        }
                    );
                }
            );
        });
    </script>

And my menu looks like this:

<ul class="menu">
<li><a href="#nyheder"><br>Nyheder<b class="nyhedfarve">+</b></a></li>
<li><a href="#events"><br>Events<b class="eventfarve">+</b></a></li>
<li><a href="#musik"><br>Musik<b class="musikfarve">+</b></a></li>
<li><a href="#in"><br>Hvad rør sig?<b class="infarve">+</b></a></li>
<li><a href="#portrait"><br>Portræt<b class="portraitfarve">+</b></a></li>
<li><a href="#om"><br>Om Street News<b class="omfarve">+</b></a></li&开发者_JS百科gt;
</ul>

The tabs are working perfectly but i would love #nyheder to be the default tab, i tried with

).first().find('a').trigger('click');

but without luck.


This should click the first a link on page load:

$(document).ready(function() {
    $('a').first().click();
});

Or if you have a lot of links and want to be sure you hit the menu ones:

$('ul.menu').find('a').first().click();
0

精彩评论

暂无评论...
验证码 换一张
取 消