【问题标题】:Jquery doesn't have a selector for "no class" [duplicate]Jquery没有“无类”的选择器[重复]
【发布时间】:2014-08-18 19:29:41
【问题描述】:

我有一些表格,我只需要在这个表格中保留一些内容,所以我有这个

 $(truc).find('tr').each(function(lig) {
        if (lig != 0 && (!$(this).children(':first').not('')) && (!$(this).children(':first').hasClass('main-title')) && (!$(this).children(':first').hasClass('top-top-title'))) {
            $(this).remove();
        }
        ;
    }

我需要(!$(this).children(':first').not('')) 的帮助,因为我需要选择第一个孩子没有班级(甚至没有空班)的行并且我不知道我需要哪些指令

编辑:我解决了自己检查$(this).children(':first')是否有属性类的问题 $(this).children(':first').attr('class'),所以如果一个元素没有类,它就不会进入if

【问题讨论】:

  • 这是我的变量,里面有表格
  • 脏流已经给出了你的问题的答案..
  • 您可以获取类属性并将其与''进行比较。只需遍历孩子。
  • 我已经看到了这个问题,但是我不知道如何使用答案,或者它们不起作用,我尝试了 $(this).children(':first').not( '班级'); $(this).children(':first').not('[class]'); $(this).children(':first').not([class]),同样的结果

标签: jquery selector


【解决方案1】:

试试

!$(this).children(':first').get(0).className

【讨论】:

  • 似乎不起作用,我的结果相同。
【解决方案2】:

检查属性,像这样

(!$(this).children(':first').not('[class]'))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-11
    • 2017-07-23
    • 1970-01-01
    • 2017-06-24
    相关资源
    最近更新 更多