如何从jQuery选择中排除这些元素? [英] How can I exclude these elements from a jQuery selection?

查看:97
本文介绍了如何从jQuery选择中排除这些元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$("ul.dropdown ul").slideDown("slow");
$("ul.dropdown ul ul").children().hide();

这会导致匹配第二个选择器的那些显示短暂的时间。如何从第一个集合中排除第二个集合,并只显示第一个集合?

That causes the ones that match the second selector to display for a brief time. How can I exclude the second set from the first set, and only show the first set?

    <ul class="dropdown">
        <li style="margin: 0px">
            <span id="header">
                <img src="back.gif" alt='background' style="border:none;" />                        
                <span style="position: absolute; top: 5px; left: 2px;">
                    <img src="button.gif" style="border:none;" />
                </span>                 
                <span style=" position: absolute; top: -5px; left: 70px;">
                    <p style="background-color: white; width: 200px; height: 20px; font-size: 1.2em; border: 2px solid blue">Menu</p>
                </span>
            </span>
            <ul class="sub_menu">
                 <li><a href="#">Artificial Turf</a></li>
                 <li><a href="#">blah</a></li>
                 <li id="1">
                    <a id="1.1" href="#">Batting Cages</a>
                    <ul id="2">
                        <li><a href="#">Indoor</a></li>
                        <li><a href="#">Outdoor</a></li>
                    </ul>
                 </li>
                 <li><a href="#">Benches &amp; Bleachers</a></li>
                 <li><a href="#">Communication Devices</a></li>
                 <li><a href="#">Dugouts</a></li>
                 <li><a href="#">Fencing &amp; Windscreen</a></li>
                 <li><a href="#">Floor Protectors</a></li>
                 <li><a href="#">Foul Poles</a></li>
                 <li><a href="#">Netting</a></li>
                 <li><a href="#">Outdoor Furniture &amp; Storage</a></li>
                 <li><a href="#">Outdoor Signs</a></li>
                 <li><a href="#">Padding</a></li>
                 <li><a href="#">Scoreboards</a></li>
                 <li><a href="#">Shade Structures</a></li>
                 <li><a href="#"> - VIEW ALL - </a></li>
            </ul>
        </li>
    </ul>


推荐答案

这可能会奏效:

$("ul.dropdown > li > ul").slideDown("slow");

>表示只有直接的孩子( http://docs.jquery.com/Selectors/child#parentchild )。所以,只要你的父母是这样的(在你的编辑刚刚,它看起来它是):

">" means only direct children (http://docs.jquery.com/Selectors/child#parentchild). So as long as your heirarchy is like this (which, after your edit just now, it appears it does):

<ul>
  <li>
    <ul>
..

它很可能工作。希望相关变化是显而易见的...

it will most likely work. Hopefully relevant variations are obvious...

这篇关于如何从jQuery选择中排除这些元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆