2013-02-27 89 views
1

我在ul> li> ul> li列表中有一個手風琴。 它有三個在頁面加載時關閉的框,但我希望在加載頁面時打開第一個框。以下是所有jQuery代碼。打開手風琴第一標籤

$(document).ready(function(){ 
    $("#nav > li > a").on("click", function(e){ 
    if($(this).parent().has("ul")) { 
     e.preventDefault(); 
    } 

    if(!$(this).hasClass("open")) { 
     // hide any open menus and remove all other classes 
     $("#nav li ul").slideUp(350); 
     $("#nav li a").removeClass("open"); 

     // open our new menu and add the open class 
     $(this).next("ul").slideDown(350); 
     $(this).addClass("open"); 
    } 

    else if($(this).hasClass("open")) { 
     $(this).removeClass("open"); 
     $(this).next("ul").slideUp(350); 
    } 
    }); 
}); 

html是一個簡單的ul> li> ul> li列表。

+0

沒關係,我做到了。我在第一個ul> li> ul.first上放了一個'.first'類和一個display:block。 – 2013-02-27 10:24:05

回答

0

如果你的菜單隻有鏈接和子鏈接(無標頭),把這個在CSS:

ul#nav li:first-child ul { 
    display:block; 
}