2011-08-21 67 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