Javascript 使用jQuery,如何检查表单元格是否为空?
使用jQuery,如何检查表单元格是否为空 请帮帮我。试试这个:Javascript 使用jQuery,如何检查表单元格是否为空?,javascript,jquery,asp.net-ajax,Javascript,Jquery,Asp.net Ajax,使用jQuery,如何检查表单元格是否为空 请帮帮我。试试这个: $content = $('#your_cell_id_here').html(); if($content == '') { // yes it is empty } else { // no it is not empty } 您可以将CSS选择器与函数一起使用,以获取对单元格元素的引用,然后使用函数查看它是否包含任何内容。例如,如果单元格的ID为“foo”: 您可以将css类添加到表及其行和列中,然后使用获取表项
$content = $('#your_cell_id_here').html();
if($content == '')
{
// yes it is empty
}
else
{
// no it is not empty
}
您可以将CSS选择器与函数一起使用,以获取对单元格元素的引用,然后使用函数查看它是否包含任何内容。例如,如果单元格的ID为“foo”:
您可以将css类添加到
表及其行和列中,然后使用获取表项:
if ( !($('#mytable tr.row-i td.column-j').html()) ) { alert("empty"); }
你说空是什么意思
//cell maycontain new lines,spaces,&npsp;,... but no real text or other element
$("cellselector").text().trim()=="";
或
//单元格根本没有子元素,甚至没有文本,例如。
$(“单元格选择器:空”)
您可以使用我在这里发布的技术
如果您已经知道要检查的单元格的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
}
})) 相关人士:谢谢。但所有这些都只能在IE中使用,而不能在Firefox中使用。我现在检查过了。在IE7、FF3.5、Chrome3、Safari4和Opera10中测试并运行。测试页面:预期输出:“foo有内容/条为空”确保允许空白;您可能需要修剪html
返回的字符串。
$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
}