循环输入和选择元素,并隐藏上一个td

loop through input and select elements and hide the previous td

本文关键字:隐藏 上一个 td 元素 输入 选择 循环      更新时间:2023-09-26

下面的代码循环遍历div中的所有inputselect元素,并检查值是否为空,然后隐藏它,它可以完美地工作:

$("#customfields_1 :input").filter(function() {
    return $.trim(this.value).length === 0;
}).hide();

但现在我真正想要的是隐藏以前的td,类似这样的东西:

$("#customfields_1 :input").filter(function() {
    return $.trim(this.value).length === 0;
}).prev('td').hide();

我想您想要.parent('td').hide();.closest('td').hide();

在使用.prev()之前遍历到td

.closest("td").prev("td").hide();

并回顾jQuery中的DOM遍历API。