【发布时间】:2021-01-07 19:45:55
【问题描述】:
我需要隐藏this page 中间表格上的最后一个“购买地点”列。此列有数百个产品页面,始终位于最后,但并不总是位于第 4、5 等(例如,某些表格的列比其他表格多)。
<table class="table">
<thead>
<tr>
<th>Part #</th>
<th>Description</th>
<th>Dimensions in. (mm)</th>
<th>Uniformly Distributed Load lbs. (kg)</th>
<th>Containment Capacity gal. (L)</th>
<th>Weight lbs. (kg)</th>
<th>Where to Buy</th>
</tr>
</thead>
<tbody>
<tr>
<td class="toggler"><span class="cellLabel">Part #</span> 1000
</td>
<td><span class="cellLabel">Description</span> 4-Drum Spill Pallet, without drain
</td>
<td><span class="cellLabel">Dimensions in. (mm)</span> 53 x 53 x 11¾ (1347 x 1347 x 299)
</td>
<td><span class="cellLabel">Uniformly Distributed Load lbs. (kg)</span> 6,000 (2722)
</td>
<td><span class="cellLabel">Containment Capacity gal. (L)</span> 66 (250)
</td>
<td><span class="cellLabel">Weight lbs. (kg)</span> 90.0 (41.0)
</td>
<td><span class="cellLabel">Where to Buy</span>
<div class="ps-widget ps-enabled" ps-sku="1000" tabindex="0" aria-disabled="false" role="button" aria-label="Find where to buy this product" style="display: block; visibility: visible;"><span class="ps-button-label">Buy Now</span></div>
</td>
</tr>
<tr>
<td class="toggler"><span class="cellLabel">Part #</span> 1001
</td>
<td><span class="cellLabel">Description</span> 4-Drum Spill Pallet, with drain
</td>
<td><span class="cellLabel">Dimensions in. (mm)</span> 53 x 53 x 11¾ (1347 x 1347 x 299)
</td>
<td><span class="cellLabel">Uniformly Distributed Load lbs. (kg)</span> 6,000 (2722)
</td>
<td><span class="cellLabel">Containment Capacity gal. (L)</span> 66 (250)
</td>
<td><span class="cellLabel">Weight lbs. (kg)</span> 90.0 (41.0)
</td>
<td><span class="cellLabel">Where to Buy</span>
<div class="ps-widget ps-enabled" ps-sku="1001" tabindex="0" aria-disabled="false" role="button" aria-label="Find where to buy this product" style="display: block; visibility: visible;"><span class="ps-button-label">Buy Now</span></div>
</td>
</tr>
</tbody>
</table>
我已经尝试了我在网上找到的下面的 jQuery,它可以隐藏标题,但我不知道如何隐藏 TD 的东西。
表格有一个 .table 类,但我不能只使用 CSS 隐藏最后一个孩子,因为其他表格使用相同的类(非常感谢网络代理!)。
// Hide WTB column - MPT 1-7-2021
$('.table th:contains("Where to Buy")').css('display', 'none')
if($(".table").hasClass('ps-widget')){
$(".ps-widget").hide();
}
【问题讨论】:
-
另外,您说过要隐藏最后一个表格列,但您的尝试会根据内容和类名显示其他内容。请修改以更明确您的目标。
-
也可以通过
:contains一起使用来获取列索引。