Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 如果没有tr,则隐藏表_Jquery_Html - Fatal编程技术网

Jquery 如果没有tr,则隐藏表

Jquery 如果没有tr,则隐藏表,jquery,html,Jquery,Html,我正在输出此表: <table class="table-example"> <thead> <tr> <th scope="col">Location</th> <th scope="col">Description</th> <th scope="col">Status</th> <th scope="col">E

我正在输出此表:

<table class="table-example">
  <thead>
    <tr>
      <th scope="col">Location</th>
      <th scope="col">Description</th>
      <th scope="col">Status</th>
      <th scope="col">Eta Fix</th>
    </tr>
  </thead>
  <tbody></tbody>
</table>
我做错了什么

试试这个:

$(函数(){
if($(“.table example>tbody>tr”).length==null | |$(“.table example>tbody>tr”).length==0){
$(“.table example”).hide();
}
});

位置
描述
地位
埃塔修正案
您可以使用
.table example>tbody>tr
,但
$('.table example').hide()中缺少'。
我希望它能对您起作用。

如果表中有tbody标记,选择器$('.table example>tbody')将返回长度为1的值。相反,您需要检查tbody中的任何元素:

$(function(){
  if ($('.table-example tbody *').length == 0){
    $('.table-example).hide();
  }
});

可以将
:has
选择器或方法与
:empty
选择器一起使用

$('.table example').has('tbody:empty').hide()

位置
描述
地位
埃塔修正案

您要查找的是表格示例中的tbody元素的数量,而不是tr元素。将选择器更改为“.table example>tbody tr”
$(function () {

  if ($('.table-example > tbody > tr').length == 0){
    $('.table-example').hide();
  }

});
$(function(){
  if ($('.table-example tbody *').length == 0){
    $('.table-example).hide();
  }
});