试试
<script language="javasxcript">
function changecolor()
{
  document.all.inputname.style="background:red"
}
</script>

解决方案 »

  1.   

    鼠标是onClick,onMouseDown,键盘才有onKeyDown
      

  2.   

    这样试了但是没有成功,是数组的关系吗?<script language="javasxcript">
    function changecolor()
    {
      document.all.textdata_A[].style="background:red" ;
        document.all.textdata_B[].style="background:red" ;
          document.all.textdata_C[].style="background:red" ;
            document.all.textdata_D[].style="background:red" ;
    }
    </script><?php
        do{ echo "<tr  height=40 bgcolor=#cccccc >" ;
    echo "<td >".$row['VT4_0']."<font color=#FF0000>".$row['VT4_1']."</font></td>";
    echo "<td ><input name=textdata_A[] type=text onClick=changecolor()></td>";
    echo "<td ><input name=textdata_B[] type=text onClick=changecolor()></td>";
    echo "<td ><input name=textdata_C[] type=text onClick=changecolor()></td>";
    echo "<td ><input name=textdata_D[] type=text onClick=changecolor()></td>";
    echo "</tr>";

     } while ($row= mssql_fetch_assoc($query)); ?>
      

  3.   

    <input name=T1 size=20 onKeyDown="this.style.background='red';">获得焦点时好用~~~
      

  4.   

    以上是键盘触发~~~鼠标的:<input name=T1 size=20 onclick="this.style.background='red';">
      

  5.   

    感谢各位前辈给予的帮助,经过修正底下写的会比较适合 
    感谢 zltostem(尘寞)给予的帮助.<input name="textdataA" type=text onfocusout="this.style.background='#ffffff'" onfocusin="this.style.background='#cccccc'">
    <input name="textdataB" type=text onfocusout="this.style.background='#ffffff'" onfocusin="this.style.background='#cccccc'">
    <input name="textdataC" type=text onfocusout="this.style.background='#ffffff'" onfocusin="this.style.background='#cccccc'">
    <input name="textdataD" type=text onfocusout="this.style.background='#ffffff'" onfocusin="this.style.background='#cccccc'">