我有下面的示例表,有时它有内容,但有时没有.
我如何使用jquery,这样如果没有td(或者只有1行tr)我会隐藏整个表格?
example 1:
<table>
<tr><th>some title</th></tr>
</table>
example 2:
<table>
<tr><th>some title</th></tr>
<tr><td>some content</td></tr>
</table>
Run Code Online (Sandbox Code Playgroud)
我试过了,但似乎没有用.
$('table').each(function() {
if ($(this).find('td:empty').length) $(this).remove();
});?
Run Code Online (Sandbox Code Playgroud)
改为:
JS
$('table').each(function() {
if($(this).find('tr').children("td").length < 1) {
$(this).hide();
}
});
Run Code Online (Sandbox Code Playgroud)
你想隐藏你的桌子?如果是,我建议使用hide()cause remove(),从DOM中删除元素.
| 归档时间: |
|
| 查看次数: |
3489 次 |
| 最近记录: |