<table border="1" cellspacing="0" width="400" cellpadding="0" id="table1">
    <tr>
      <td width="80"><input type="text" value="12"></td>
      <td width="80"><input type="text" value="324"></td>
      <td width="80"><input type="text" value="56"></td>
      <td width="80"><input type="text" value="78"></td>
      <td width="80"><input type="text" value="90"></td>
    </tr>
    <tr>
      <td width="80"><input type="text" value="abc"></td>
      <td width="80"><input type="text" value="def"></td>
      <td width="80"><input type="text" value="ghj"></td>
      <td width="80"><input type="text" value="lop"></td>
      <td width="80"><input type="text" value="dry"></td>
    </tr>
    <tr>
      <td width="80"><input type="text" value="!@#"></td>
      <td width="80"><input type="text" value="_(*"></td>
      <td width="80"><input type="text" value="#$%"></td>
      <td width="80"><input type="text" value="^$#"></td>
      <td width="80"><input type="text" value="WWW"></td>
    </tr>
  </table><SCRIPT>
var ids;
var idstext;
function hightlight_td(){
var text=txt.value;
TDs=document.all.table1.all.tags("TD")
//使用iframe时:
//TDs=iframe的name.document.all.table1.all.tags("TD")
 if (text!="")
 {
  for (var i = 0; i < TDs.length; i++)
  {
   obj=TDs[i].childNodes[0];
   idstext=obj.value;
   idnum=idstext.indexOf(text);
   if (idnum!=-1)
   {
 obj.style.background="red";
   }
   else
   {
 obj.style.background="#FFFFFF";
   }
  }
 }
 else
 {
  alert("没有输入");
 }
}
</SCRIPT>
<p align="center"><input type="text" name="txt" value=""><input type="button" value="请输入要查的字符串." onClick="hightlight_td();"></p>

解决方案 »

  1.   

    TRY:新代码:
    <table border="1" cellspacing="0" width="400" cellpadding="0" id="table1">
        <tr>
          <td width="80"><input type="text" value="12"></td>
          <td width="80"><input type="text" value="324"></td>
          <td width="80"><input type="text" value="56"></td>
          <td width="80"><input type="text" value="78"></td>
          <td width="80"><input type="text" value="90"></td>
        </tr>
        <tr>
          <td width="80"><input type="text" value="abc"></td>
          <td width="80"><input type="text" value="def"></td>
          <td width="80"><input type="text" value="ghj"></td>
          <td width="80"><input type="text" value="lop"></td>
          <td width="80"><input type="text" value="dry"></td>
        </tr>
        <tr>
          <td width="80"><input type="text" value="!@#"></td>
          <td width="80"><input type="text" value="_(*"></td>
          <td width="80"><input type="text" value="#$%"></td>
          <td width="80"><input type="text" value="^$#"></td>
          <td width="80"><input type="text" value="WWW"></td>
        </tr>
      </table><SCRIPT>
    var ids;
    var idstext;
    function hightlight_td(){
    var text=txt.value;
    TDs=document.all.table1.all.tags("TD")
    //使用iframe时:
    //TDs=iframe的name.document.all.table1.all.tags("TD")
     if (text!="")
     {
      for (var i = 0; i < TDs.length; i++)
      {
       obj=TDs[i];
       idstext=obj.childNodes[0].value;
       idnum=idstext.indexOf(text);
       if (idnum!=-1)
       {
     obj.childNodes[0].style.background="red";
       }
       else
       {
     obj.childNodes[0].style.background="#FFFFFF";
       }
      }
     }
     else
     {
      alert("没有输入");
     }
    }
    </SCRIPT>
    <p align="center"><input type="text" name="txt" value=""><input type="button" value="请输入要查的字符串." onClick="hightlight_td();"></p>
      

  2.   

    <table border="1" cellspacing="0" width="400" cellpadding="0" id="table1">
        <tr>
          <td width="80"><input type="text" value="12"></td>
          <td width="80"><input type="text" value="324"></td>
          <td width="80"><input type="text" value="56"></td>
          <td width="80"><input type="text" value="78"></td>
          <td width="80"><input type="text" value="90"></td>
        </tr>
        <tr>
          <td width="80"><input type="text" value="abc"></td>
          <td width="80"><input type="text" value="def"></td>
          <td width="80"><input type="text" value="ghj"></td>
          <td width="80"><input type="text" value="lop"></td>
          <td width="80"><input type="text" value="dry"></td>
        </tr>
        <tr>
          <td width="80"><input type="text" value="!@#"></td>
          <td width="80"><input type="text" value="_(*"></td>
          <td width="80"><input type="text" value="#$%"></td>
          <td width="80"><input type="text" value="^$#"></td>
          <td width="80"><input type="text" value="WWW"></td>
        </tr>
      </table><SCRIPT>
    function find_txt(){
    text=document.getElementById("txt").value;
    if(text==""){
    alert("没有输入");
    return;
    }
    tds=document.getElementById("table1").getElementsByTagName("input");
    for(var i=0;i<tds.length;i++){
    findt=tds[i].value.indexOf(text);
    if(findt!=-1){
    tds[i].style.backgroundColor="#ff0000";
    }else{
    tds[i].style.backgroundColor="#ffffff";
    }
    }
    }
    </SCRIPT>
    <p align="center"><input type="text" name="txt" id="txt" value=""><input type="button" value="请输入要查的字符串." onClick="find_txt();"></p>