【问题标题】:How to select the inverse of the selection如何选择选择的倒数
【发布时间】:2010-09-13 10:53:01
【问题描述】:

我成功选择了<ul>中的第一个<li>

我想选择除当前选择的 <li> 之外的其余 <li> 。即,(逆)。

如何选择它?

根据要求编辑

var newEle = $(str); //str contains a <li> i.e., <li>Some content</li>
$(newEle).hide();

【问题讨论】:

  • 您能发布您当前使用的脚本吗?可能它只是一个插入!或 .not() 某处,但如果我们有你的例子会更容易。

标签: javascript jquery jquery-selectors


【解决方案1】:

假设您的选择结果是一个数组,您可以使用 jQuery 方法 pop()splice(begin,end) 来选择您想要的元素。两者都记录在 here(就在“布尔默认”标题之前)。

【讨论】:

    【解决方案2】:

    http://api.jquery.com/not-selector/ 解决了我的问题

    【讨论】:

      【解决方案3】:

      你需要这样的东西吗:

      <ul id='myUL'>
        <li>One</li>
        <li>Two</li>
        <li>Three</li>
      </ul>
      

      jquery

      $('ul#myUL > li').each(function(index) {
           if( index !=  '0'){
                alert(index + ': ' + $(this).text());
           }
      });
      

      Check

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-04-01
        • 1970-01-01
        • 1970-01-01
        • 2013-12-12
        • 2019-12-18
        • 2019-12-04
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多