62,046
社区成员
发帖
与我相关
我的任务
分享
var tableList=pent.getElementsByTagName('TABLE');
if(tableList && tableList.length>0)
{
for(var i=0;i<tableList.length;i++)
{
var tdList = tableList[i].getElementsByTagName('TD');
for(var j=0;j<tdList.length;i++)
{
if(tdList[j].innerText=="")
{
//仅IE下用 tdList[j].removeNode(true);
tdList[j].parentNode.removeChild(tdList[j])
}
}
}
}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<BODY>
<table border="1" cellpadding="1" cellspacing="1" id="table1">
<tr width="200px">
<td width="200px">01</td>
<td width="200px">A</td>
</tr>
<tr>
<td width="200px">02</td>
<td width="200px">B</td>
</tr>
<tr width="200px">
<td width="200px">01</td>
<td width="200px">A</td>
</tr>
<tr>
<td width="200px">02</td>
<td width="200px">B</td>
</tr>
<tr width="200px">
<td width="200px">01</td>
<td width="200px">A</td>
</tr>
<tr>
<td width="200px">02</td>
<td width="200px">B</td>
</tr>
<tr width="200px">
<td width="200px">01</td>
<td width="200px">A</td>
</tr>
<tr>
<td width="200px">02</td>
<td width="200px">B</td>
</tr>
</table>
<input type=button value="过滤A" onclick="hide('A')">
<input type=button value="过滤B" onclick="hide('B')">
<input type=button value="恢复" onclick="hide('')">
</BODY>
</HTML>
<script>
function hide(str)
{
var table=document.getElementById('table1');
for(var i=0;i<table.rows.length;i++)
{
if(table.rows[i].cells[1].innerHTML==str)
{
table.rows[i].style.display='none';
}
else
{
table.rows[i].style.display='';
}
}
}
</script>