简体   繁体   English

jQuery展开第一个ul> li> ul父级

[英]jquery expand firlst ul>li>ul of parent

i have some jquery thats expanding/collapsing on click. 我有一些jQuery的多数民众赞成在点击扩展/崩溃。 i would like the first item to be expanded by default but im having trouble with the jquery. 我想默认扩展第一项,但是我在使用jQuery时遇到麻烦。 i've tried a few different angles to no avail. 我尝试了几种不同的角度都没有用。 any help would be much appreciated! 任何帮助将非常感激!

http://jsfiddle.net/trrJp/1/ http://jsfiddle.net/trrJp/1/

If your issue is only you want the first item to open, after you setup all the menu jquery you can do something like this: 如果仅是您要打开的第一项,那么在设置所有菜单jquery之后,您可以执行以下操作:

$('#menu li:first').slideToggle();

Or you could simulate a click: 或者您可以模拟一次点击:

$('#menu li:first').click();

The actual code is dependent on your actual implementation and how you'd open it but the general idea is to trigger the first element to open. 实际的代码取决于您的实际实现以及如何打开它,但是一般的想法是触发第一个元素打开。

You can keep the first item expanded by default with the following line 您可以在默认情况下使用以下行将第一项扩展

  $('#collapser li:first-child > ul').show();

What it does is selects the first li and then select the ul within that li and show that. 它的作用是选择第first li ,然后选择该liulshow出来。

First Child Selector 第一个孩子选择器

Working Fiddle 工作小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM