2009-12-22 107 views

回答

1

试试这个:

$content = $('#your_cell_id_here').html(); 

if($content == '') 
{ 
    // yes it is empty 
} 
else 
{ 
    // no it is not empty 
} 
5

您可以使用CSS选择器与$函数获取细胞的元素的引用,然后使用html功能,看是否有任何内容。例如,如果该小区有ID为“foo”:

if ($("#foo").html()) { 
    // The cell has stuff in it 
} 
else { 
    // The cell is empty 
} 
+0

谢谢。但所有这些只适用于IE而非Firefox。我现在检查了它。 – Yaswanth 2009-12-22 12:06:20

+2

经过测试,适用于IE7,FF3.5,Chrome3,Safari4和Opera10。测试页面:http://pastie.org/753004预期输出:“foo的内容/栏为空”确保允许空格;你可能想修剪'html'返回的字符串。 – 2009-12-22 12:24:31

0

你可以CSS类添加到您的table及其行和列,然后使用jquery selectors得到表项目:

if (!($('#mytable tr.row-i td.column-j').html())) { alert("empty"); } 
10

你什么意思是空的。

//cell maycontain new lines,spaces,&npsp;,... but no real text or other element 
$("cellselector").text().trim()==""; 

//cell has no child elements at all not even text e.g. <td></td> 
$("cellselector:empty") 
0

你可以使用我张贴在这里

http://www.keithrull.com/2010/06/09/HowToChangeTableCellColorDependingOnItsValueUsingJQuery.aspx

你可以使用这个,如果你已经知道你要检查

小区ID的trechnique
$valueOfCell = $('#yourcellid').html(); 

或者可以在桌子上的单元迭代

$("#yourtablename tr:not(:first)").each(function() {       
//get the value of the table cell located    
//in the third column of the current row    
var valueOfCell = $(this).find("td:nth-child(3)").html();       
//check if its greater than zero    
if (valueOfCell == ''){     
    //place action here 
}    
else{     
    //place action here 
}   

});

相关问题