Javascript Jquery css选择器如果没有数据,则应用样式
大家好,我有一个重复表,其中有许多TR行,如下所示:Javascript Jquery css选择器如果没有数据,则应用样式,javascript,jquery,css,Javascript,Jquery,Css,大家好,我有一个重复表,其中有许多TR行,如下所示: <table> <tr class="RowStyle" style="background-color:White;"> <td>field 1</td> <td>field 2</td> <td>field 3</td> <td class="select
<table>
<tr class="RowStyle" style="background-color:White;">
<td>field 1</td>
<td>field 2</td>
<td>field 3</td>
<td class="selector">field 4</td>
<td>field 5</td>
</tr>
<tr class="RowStyle" style="background-color:White;">
<td>field 1</td>
<td>field 2</td>
<td>field 3</td>
<td class="selector"> </td>
<td>field 5</td>
</tr>
<tr class="RowStyle" style="background-color:White;">
<td>field 1</td>
<td>field 2</td>
<td>field 3</td>
<td class="selector"> </td>
<td>field 5</td>
</tr>
我需要了解如何说如果text=nothing或更改背景样式,有人能帮我吗?这里是…试试这个:
$('.selector').each(function(){
if (!$(this).text().trim().length) {
$(this).closest('.RowStyle').css('background-color', 'red');
}});
试试这个:
$('.selector').each(function(){
if (!$(this).text().trim().length) {
$(this).closest('.RowStyle').css('background-color', 'red');
}});
试试看
if ( !$('.selector').text().length || $('.selector').html() == ' ' ) {
$(this).parent().css('background-color', 'red');
}
试一试
试试看
试试看
试试这个
$('.selector').each(function(i, element){
if($(element).text().trim().length == 0)
{
$(element).parent().css('background-color', 'red');
}
});
试试这个
$('.selector').each(function(i, element){
if($(element).text().trim().length == 0)
{
$(element).parent().css('background-color', 'red');
}
});
(1):
.text()
/.html()
而不是.val()
(2)是
而不是
尝试了。。。无济于事。如果($('.selector').text()=''{$('.RowStyle').css('background-color','red');}是,请使用text().trim().length==0(1):.text()
/.html()
而不是.val()
(2)它是
而不是尝试的。。。无济于事。如果($('.selector').text()=''){$('.RowStyle').css('background-color','red');}是,请使用text().trim().length==0@RohitAzad为什么?我错过了什么吗?@RohitAzad为什么。。?我遗漏了什么吗。。?