【发布时间】:2010-12-29 02:03:32
【问题描述】:
使用jQuery,如何检查表格单元格是否为空?
请帮帮我。
【问题讨论】:
标签: javascript jquery asp.net-ajax
使用jQuery,如何检查表格单元格是否为空?
请帮帮我。
【问题讨论】:
标签: javascript jquery asp.net-ajax
你说的空是什么意思。
//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")
【讨论】:
【讨论】:
html返回的字符串。
试试这个:
$content = $('#your_cell_id_here').html();
if($content == '')
{
// yes it is empty
}
else
{
// no it is not empty
}
【讨论】:
您可以将 css 类添加到您的 table 及其行和列,然后使用 jquery selectors 获取表格项:
if ( !($('#mytable tr.row-i td.column-j').html()) ) { alert("empty"); }
【讨论】:
你可以使用我在这里发布的技巧
http://www.keithrull.com/2010/06/09/HowToChangeTableCellColorDependingOnItsValueUsingJQuery.aspx
如果您已经知道要检查的单元格的 ID,则可以使用它
$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
}
});
【讨论】: