还是表格操作的问题,请帮忙 :)
以下代码已经实现通过输入条件过滤出符合条件的行, 但只能搜索首列的单元格.
如果不管有多少行多少列,只要是有符合条件的单元格,就把它的整行显示出来,请问该怎么弄?
<html>
<head>
<title> </title>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 " />
</head>
<body>
<center>
<script type= "text/javascript ">
function Search(Tbl,TextValue)
{
var count=0;
var keyWord=TextValue.value;
if(keyWord!= " ")
{
for(var i=0;i <Tbl.rows.length;i++)
{
var tr=Tbl.rows[i];
if(tr.firstChild.innerHTML.indexOf(keyWord)==-1)
tr.style.display= "none ";
else
{
tr.style.display= "block ";
count++;
}
}
}
if(count==0)
{
alert( '找不到你要的记录! ');
ListAll();
}
}
function ListAll(Tbl)
{
for(var i=0;i <Tbl.rows.length;i++)
{
Tbl.rows[i].style.display= "block ";
}
}
</script>
<input name= "ttt " type= "text " style= "width:200 ">
<input type= "button " value= "查找 " onclick= "Search(Tbl1,ttt) " >
<input type= "button " value= "返回 " onclick= "ListAll(Tbl1) ">
<br>
<table width= "300 " id= "Tbl1 " border= "1 ">
<tr> <td> aaa </td> <td> 12 </td> </tr>
<tr> <td> 呵呵 </td> <td> 56 </td> </tr>
<tr> <td> ccc </td> <td> b5 </td> </tr>
<tr> <td> ddd </td> <td> 12 </td> </tr>
<tr> <td> 呵呵 </td> <td> a4 </td> </tr>
<tr> <td> ddeed </td> </tr>
<tr> <td> ddafd </td> </tr>
</table>
</center>
</body>
</html>
------解决方案-------------------- if(tr.firstChild.innerHTML.indexOf(keyWord)==-1)
tr.style.display= "none ";
把firstChild去掉就是查找整行的了
if(tr.innerHTML.indexOf(keyWord)==-1)
tr.style.display= "none ";
这样可以