Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/39.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/hadoop/6.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隐藏a<;TD>;如果他有一个&引用;(空格,而不是空格)_Jquery_Css - Fatal编程技术网

jQuery隐藏a<;TD>;如果他有一个&引用;(空格,而不是空格)

jQuery隐藏a<;TD>;如果他有一个&引用;(空格,而不是空格),jquery,css,Jquery,Css,HTML代码 <table class="wrap_class_adv"> <tr> <td>321</td> <td>123</td> <td> </td> <--- HERE </tr> </table> 如何使用visibility:hidden隐藏包含空格的TD?您忘记链接jQuery,而尝

HTML代码

<table class="wrap_class_adv">
    <tr>
        <td>321</td>
        <td>123</td>
        <td> </td>    <--- HERE
    </tr>
</table>


如何使用visibility:hidden隐藏包含空格的TD?

您忘记链接jQuery,而尝试设置
class
,但设置
css

看我的小提琴:

<table class="wrap_class_adv">
    <tr>
        <td>321</td>
        <td>123</td>
        <td> </td>
    </tr>
</table>

<script>
$('.wrap_class_adv td').each(function () {
    if ($(this).text() === " ") {
        $(this).addClass('hidden');
    }
});
</script>

<style>
    td {border:1px solid #000;}
    .hidden {visibility: hidden;}
</style>

321
123
$('.wrap\u class\u adv td')。每个(函数(){
如果($(this).text()=“”){
$(this.addClass('hidden');
}
});
td{border:1px solid#000;}
.hidden{可见性:hidden;}


注意:不要忘记链接jQuery。

如果要隐藏任何包含空格的元素,即使它包含其他文本,也可以使用包含选择器,如下所示

$("td:contains(' ')")
如果要隐藏仅包含空格字符的元素,则可能必须将其全部选中,然后迭代结果并检查其内容:

$('td').each(function() {
    if ($(this).html() == ' ')
        $(this).css('visibility', 'hidden');
});

你在正确的轨道上。对于每个
tr
您都试图找到包含空格的
td

您可以做的是,在
td
上执行
filter
,只返回那些包含空格的
td
,然后根据需要更改
css

注意:有一个或多个空间,甚至没有空间,只是空的都没有关系。但是,如果存在
,则不会像您在问题标题中提到的那样受到影响

$('.wrap\u class\u adv tr')。每个(函数(){//用于每个tr
$(this.find(“td”).filter(函数(){//filter td
return(this.innerText==“”);//其innerText为空
}).css(“可见性”、“隐藏”);//将可见性应用于css
});
td{border:1px solid#000;padding:4px;}

321
123

尝试将类设置为td:

这里的代码完全符合您的要求,隐藏了td而不是tr

CSS:

JS:


可见性更好,显示:无,您还需要担心保留表布局、colspan等@dfsq:在这种情况下,删除
边框
是否也这样做?根据被否决的答案,请告诉我们您指的是a(数字1)空间还是多个空间(a的一般含义)?
$('td').each(function() {
    if ($(this).html() == ' ')
        $(this).css('visibility', 'hidden');
});
td {
border:1px solid #000;
}
.hidden {
    display: none;
}
$(document).ready(function () {
$('.wrap_class_adv tr').each(function () {
    $(this).find('td').each(function () {
        if($(this).text().trim() === "")
        $(this).addClass('hidden');
    });
});
});