function tovalidate(){
var first = document.getElementById("first");
var second = document.getElementById("second");
if(first.value=="1"){
first.style.backgroundColor="red";
//first.style.backgroundImage="";图
}
if(second.value=="2"){
second.style.backgroundColor="blue";
}
}页面
    输入1: <input type="text" id="first"    />
            输入2: <input type="text" id="second"    />
            <input type="button" value="test"   onclick="tovalidate()" />

解决方案 »

  1.   


    <input type=hidden id="hidInf" value=0>
    <table border="1" width="100%" id=myTab>
    <tr>
    <td> </td>
    <td> </td>
    </tr>
    <tr>
    <td> </td>
    <td> </td>
    </tr>
    </table>
    <script language="javascript">
    <!--
    function $(id){return document.getElementById(id)}
    $("myTab").style.backgroundImage="url("+($("hidInf").value==1?"http://s.vdoing.com/icon/vd02.gif":"http://www.csdn.net/ui/images/gongshang_logos.gif")+")"
    //-->
    </script>
      

  2.   

    可以放在
    <body onload="tovalidate()">