2011-08-21 66 views
0

我有li列表與哪個exapands罰款,如果我點擊李,但我希望它擴大,如果我點擊鏈接'一'不是李。show hide使用jquery嵌套ul(s)?

我該如何讓jquery下面的工作不在李?

下面

的代碼是我到目前爲止:

$("#leftcontent ul li:not(:has(li.current))").find("ul").hide().end() // Hide all other ULs 
    .click(function(e) { 
     if (this == e.target) { // if the handler element is where the event originated 
      $(this).children('ul').slideToggle('fast'); 
     } 
}); 
+0

分享你的標記......當你問一整套代碼時,它很漂亮。把它扔給我們,我們喜歡在裏面游泳。 – Shef

+0

一些HTML會很好,一個JSFiddle會更好... –

+0

是啊,我們需要看到一些HTML – stefmikhail

回答

4

試試這個:

$("#leftcontent li > a").click(function() { 
    // get the parent <li> of the <a> 
    var li = $(this).closest('li'); 
    // open the child <ul> of the <li> 
    li.find(' > ul').slideToggle('fast'); 
}); 

測試在這裏:http://jsfiddle.net/Ye6U5/

,並隱藏嵌套ULS爲onload:

$(function() { 
    $("#leftcontent li > ul").hide(); 
}); 

http://jsfiddle.net/Ye6U5/1/

+0

這工作完美...現在有沒有辦法我可以隱藏左內嵌uls加載? – user520300

+0

是的,更新了答案 – arnaud576875

+0

甜美!謝謝! – user520300