【问题标题】:If class other than my class is present如果我的班级以外的班级在场
【发布时间】:2013-04-26 00:21:38
【问题描述】:

我有一个看起来像这样的动态列表

<li>item 1</li>
<ii>item 2</li>
<ii class="route2">item 2</li>
<ii>item 3</li>
<ii>item 4</li>

还有两个按钮

<button>Route one</button>
<button>Route two</button>

只有当所有列表项都具有 route2 类时,我才无法显示路由 2 按钮。

【问题讨论】:

    标签: javascript jquery css-selectors


    【解决方案1】:

    一种可能的方式:

    $("button:eq(1)").toggle( !$("li:not(.route2)").length );
    

    演示: http://jsfiddle.net/CNP7Z/

    【讨论】:

      【解决方案2】:

      这应该可行:

      if ( $('li').not('.route2').length ){
          $('button').hide();
      }
      

      【讨论】:

        猜你喜欢
        • 2019-04-26
        • 1970-01-01
        • 2018-05-20
        • 2012-09-06
        • 1970-01-01
        • 1970-01-01
        • 2011-08-09
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多