无法删除 jQuery 变量中的嵌套列表

发布于 2024-08-24 00:16:24 字数 2134 浏览 7 评论 0原文

我有一个嵌套的有序列表,我使用此代码对其进行动画处理...

               var $li = $("ol#update li");
                function animate_li(){
                   $li.filter(':first')
                      .animate({
                         height:  'show',
                         opacity: 'show'
                      }, 500, function(){
                        animate_li();
                      });
                  $li = $li.not(':first');
                }
                animate_li();

现在我想要显示嵌套列表(ol s)或 ols 中的 li 或对其进行动画处理,

请看一下示例此处

我的 ols 的结构是

 <ol>
 <li class="bar248">
        <div class="nli">
        <div class="pic">
            <img src="dir/anonymous-thumb.png"alt="image" />
        </div>
        <div align="left" class="text">
        <span>
                <span class="delete_button"><a href="#" id="test" class="delete_update">R</a></span>

                test shouted <span class="timestamp"> 2010/02/24 18:34:26 </span> <br />
        this
        </span>
        </div>

        <div class="clear"></div>
        </div>
        <div class="padd">

        </div>
        <ol class="comment">
            <li>                       
                    <div>Testing </div>
            </li>
            <li>
                    <div>Another Test </div>
            </li>

        </ol>

    </li>

  </ol>

我可以使用此代码隐藏嵌套的 ols ...

      $("ol#update li ol").hide();

但是尽管它们是隐藏的,但仍然消耗时间来对它们进行动画处理

我无法使用此代码删除嵌套的 li

var $li = $("ol#update li").not("ol#update li ol");
$li = $li.not("ol#update li ol");

看看这个 此处

任何帮助,

谢谢
巴杜

I have a nested oredered list which i m animating using this code...

               var $li = $("ol#update li");
                function animate_li(){
                   $li.filter(':first')
                      .animate({
                         height:  'show',
                         opacity: 'show'
                      }, 500, function(){
                        animate_li();
                      });
                  $li = $li.not(':first');
                }
                animate_li();

now i want not to show or animate the nested lists(ol s) or the li s in the ols

take a look at the example here

The structure of my ols are

 <ol>
 <li class="bar248">
        <div class="nli">
        <div class="pic">
            <img src="dir/anonymous-thumb.png"alt="image" />
        </div>
        <div align="left" class="text">
        <span>
                <span class="delete_button"><a href="#" id="test" class="delete_update">R</a></span>

                test shouted <span class="timestamp"> 2010/02/24 18:34:26 </span> <br />
        this
        </span>
        </div>

        <div class="clear"></div>
        </div>
        <div class="padd">

        </div>
        <ol class="comment">
            <li>                       
                    <div>Testing </div>
            </li>
            <li>
                    <div>Another Test </div>
            </li>

        </ol>

    </li>

  </ol>

I m able to hide the nested ols using this code...

      $("ol#update li ol").hide();

But still time is being consumed in animating them although they are hidden

I m not able to remove the nested li s using this code

var $li = $("ol#update li").not("ol#update li ol");
$li = $li.not("ol#update li ol");

Take a look at this here

Any help

thanks
Pradyut

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你列表最软的妹 2024-08-31 00:16:24

您是否尝试过像这样设置原始列表:

var $li = $("ol#update > li");

这将仅获取作为

    的直接子级的

  1. 元素> 列表。

如果您已经设置了不带“>”的 $li,那么您可以使用“filter”从该列表中删除“嵌套”

  • 元素”:
  • var $li = $('ol#update li'); // gets all <li> elements, even the nested ones
    
    // ...
    
    var $notNested = $li.filter('ol#update > li');
    // or, if you prefer,
    var $notNested = $li.filter(':not(ol#update li ol li)');
    

    Have you tried setting up your original list like this:

    var $li = $("ol#update > li");
    

    That will get only the <li> elements that are direct children of the <ol id="update"> list.

    If you've already got $li set up without the ">", then you can remove the "nested" <li> elements from that list using "filter":

    var $li = $('ol#update li'); // gets all <li> elements, even the nested ones
    
    // ...
    
    var $notNested = $li.filter('ol#update > li');
    // or, if you prefer,
    var $notNested = $li.filter(':not(ol#update li ol li)');
    
    ~没有更多了~
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文