我正在寻找创建一个jQuery逻辑来回答:
是否有任何表格单元格不包含''或'xx'且没有'yy'类
这是我的努力 - 但它似乎非常混乱?:
$('td').filter(function(index) {
return !$(this).hasClass('yy') &&
!($(this).html().trim() == '' || $(this).html().trim() == '');
})
Run Code Online (Sandbox Code Playgroud)
您可以使用:not(),例如:
$('td:not(.yy):not(:contains(xx)):not(:empty)')
Run Code Online (Sandbox Code Playgroud)
这将检查:not()具有.yy该类的单元格,确实:not()包含"xx"和.:not() :empty
如果你需要修剪,我会离开.filter(),例如:
$('td:not(.yy)').filter(function() {
var thtml = $.trim(this.innerHTML);
return thtml != '' && thtml != 'xx';
});
Run Code Online (Sandbox Code Playgroud)
注意我正在使用,$.trim()因为并非所有浏览器都支持String.trim().