<script>
function change()
{
  var table = document.getElementById("t1");
  var tds = table.getElementsByTagName("td");
  for(var i=0; i < tds.length; i++)
  {
    tds[i].innerHTML = tds[i].innerHTML.replace("123", "<font color='red'>123</font>");
  }
}
</script><table id="t1">
<td> ewrewr123> </td>
<td> ewrewr123> </td>
<td> ewrewr123> </td>
<td> ewrewr123> </td>
</table><input type="button" value="ChangeColor" onclick="change();" />

解决方案 »

  1.   

    不过可不可以 只把 中id="t1" 下的进行变色  
    table.getElementsByTagName("td");  是不是把所有td 都变色了呀
      

  2.   

    ????
    1搂的代码就是把id="t1"的表中的所有td变颜色,你想要什么效果??????
      

  3.   

    抢分,哈
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title> new document </title>
        <meta name="generator" content="editplus" />
        <meta name="author" content="Gao YiXiang" />
        <meta name="email" content="[email protected]" />
        <meta name="keywords" content="javascript dhtml dom" />
        <meta name="description" content="I love web development." />
    </head>
    <body onload="change()">
        <script> 
    function   change() 

        var   table   =   document.getElementById("t1"); 
        var   tds   =   table.getElementsByTagName("td"); 
        for(var   i=0;   i   <   tds.length;   i++) 
        { 
            tds[i].innerHTML   =   tds[i].innerHTML.replace("123",   " <font   color='red'> 123 </font> "); 
        } 

    </script> <table   id="t1"> 
    <td>   ewrewr123>   </td> 
    <td>   ewrewr123>   </td> 
    <td>   ewrewr123>   </td> 
    <td>   ewrewr123>   </td> 
    </table> <input   type="button"   value="ChangeColor"   onclick="change();"   /> 
    </body>
    </html>
      

  4.   

    <body onload="change();">把放到change()  body 的中onload