![](/img/trans.png)
[英]Hide table row if every cell except first contains a space/is empty
[英]Hide a table row if a cell inside contains a specific word
我希望能够隐藏表格行,仅当表格内的单元格在我网站的所有页面上包含“免费”一词时。
示例页面在这里: https : //widac.com.au/event/widac-event/
如果有人能告诉我如何做到这一点 - 将不胜感激!
$('#tblId tr').each(function() {
$(this).find('td')..each(function() {
if (this.textContent.includes('Complimentary')) {
$(this).parent().hide();
}
});
});
#tblId
是该特定表的 id,我在 tr 和每个 tr 内部迭代,我调用每个 td,我匹配内容并隐藏该特定 tr
javascript:
document.querySelectorAll('td').forEach(function(td) {
if (td.textContent.includes('Complimentary')) {
td.parentElement.style.display = 'none';
}
});
jQuery:
$('td').each(function() {
if (this.textContent.includes('Complimentary')) {
$(this).parent().hide();
}
});
尽管在您的示例站点中, .tribe-tickets-form-row
具有display: block !important
,它会覆盖它。 您可以设置.opacity = 0
,尽管它仍然是可交互的。 或者你可以直接.remove()
它。
$(".tribe-events-tickets tr").each( function (el) {
$(this).children().each(function () {
var text = $(this).text();
if (text.indexOf("Complimentary") !== -1 ) {
$(this).parent().hide();
}
});
});
这会有所帮助,但首先应修改代码中的此 CSS 规则:
.tribe-tickets-form-row {
margin-top: 20px;
display: block !important;
}
删除 '!important',它不允许隐藏元素。 我希望它会有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.