accordion, tab menus, assign select class for both

风格不统一 提交于 2019-12-25 08:59:05

问题


I have two menus: the Accordion menu and Tab menu, for the Tab menu, there is an assigned class selected to a link that is opened, I want to assign the class (for example) open_menu, in the same way for the accordion menu. actually if the class open_menu will be given from the condiotion that in its ul there is an A link with class Selected, it would be much better, because the class selected given to a link is taken from the cookies, and even if the page is refreshed it comes to this link Selected. Anyway, u can see all the source here: http://jsfiddle.net/bq6tA/6/ actually the end product i want, after the refresh of the page, there will be opened the accordion's tab, as well as the Tab's menu link selected that is in this accordion's tab


回答1:


See a working demo of the following code here.

I've modified your initMenu function to add the open_menu class to the appropriate accordion (and added a CSS class to indicate that it was added by changing the background to green):

function initMenu() {
    // SNIP ...
    $('#menu li a').click(function() {
        // SNIP ...
        if ((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
            $('#menu ul:visible').slideUp('normal')
                                 .siblings('a').removeClass('open_menu');
            checkElement.slideDown('normal')
                        .siblings('a').addClass('open_menu');
            return false;
        }
    });
}

I then created a function to be called after initMenu that will trigger a click on the accordion with the same rel as the id of the currently selected item:

function showCurrentTab() {
    var curId = $('.tabcontent:visible')[0].id,
        $curLink = $('a[rel="'+curId+'"]');

    $curLink.closest('ul')
            .parent('li')
            .children('a').click();
}

To figure out what's going on here, see the API docs for closest, parent and children and relate that to your HTML structure.



来源:https://stackoverflow.com/questions/4836433/accordion-tab-menus-assign-select-class-for-both

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!