<html>
<table>
<tr>
<td  cellpadding="0" cellspacing="0"><INPUT name="1" type="text" value=""  size="2" style="background-color:#d8d8d8;" id="inputid_1" ></td>
<td  cellpadding="0" cellspacing="0"><INPUT name="2" type="text" value="0"  size="2" style="background-color:#d8d8d8;" id="inputid_2" ></td></tr></table></html>当input_2中的value="0"时,改变input_1的背景色为"red",本人对js不了解,不知道能否通过js实现(注:input_1在input_2之前)

解决方案 »

  1.   

    <html>
    <table>
    <tr>
    <td  cellpadding="0" cellspacing="0"><INPUT name="1" type="text" value=""  size="2" style="background-color:#d8d8d8;" id="inputid_1" ></td>
    <td  cellpadding="0" cellspacing="0">
    <INPUT name="2" type="text" value="2"  size="2" style="background-color:#d8d8d8;" id="inputid_2" onchange="cc()">
    </td>
    <script language="javascript">
    function cc()
    {
    if(document.getElementById("inputid_2").value == "0")
    {
    document.getElementById("inputid_1").style.backgroundColor="red";
    }
    }
    </script>
    </tr></table></html>
      

  2.   

    <html>
    <table>
    <tr>
    <td  cellpadding="0" cellspacing="0"><INPUT name="1" type="text" value=""  size="2" style="background-color:#d8d8d8;" id="inputid_1" ></td>
    <td  cellpadding="0" cellspacing="0"><INPUT name="2" type="text" value="0"  size="2" style="background-color:#d8d8d8;" id="inputid_2" onblur="if(this.value==2) document.getElementById('inputid_1').style.backgroundColor='red'" ></td></tr></table></html>
      

  3.   

    谢谢二位,还有种情况不能实现
    当input_2默认值就是"0",能否在打开页面就能让input_1的背景色改变成"red"呢?
      

  4.   

    <html>
    <body onLoad="cc()">
    <table>
    <tr>
    <td cellpadding="0" cellspacing="0"><INPUT name="1" type="text" value="" size="2" style="background-color:#d8d8d8;" id="inputid_1" ></td>
    <td cellpadding="0" cellspacing="0">
    <INPUT name="2" type="text" value="2" size="2" style="background-color:#d8d8d8;" id="inputid_2" onchange="cc()">
    </td>
    <script language="javascript">
    function cc()
    {
    if(document.getElementById("inputid_2").value == "0")
    {
    document.getElementById("inputid_1").style.backgroundColor="red";
    }
    }
    </script>
    </tr>
    </table>
    </body>
    </html>可以呀!页面可以加个onLoad="cc()"就行了
      

  5.   

    window.onload=function(){
          if(document.getElementById("input_2").value=0){
               document.getElementById("inputid_1").style.backgroundColor="red";      }
    }
      

  6.   

    各位能否帮忙改写下上面的函数
     for j=1 to 30
     for i=1 to 13 (input个数是 30 * 13) 即input最大下标是input_30_13
     当input_1_11 的 value="0" 时,input_1_1,input_1_2 ,...,input_1_11,input_1_12,input_1_13 的背景色全部变成"red" 
    谢谢各位了(一定追加分)
      

  7.   

    window.onload=function(){
      if(document.getElementById("input_2").value=0){
          for(var i=1;i<=30;i++){
               for(var j=1;j<=13;j++){
                   document.getElementById("inputid_"+i+"_"+j).style.backgroundColor="red";           }
          }
      //document.getElementById("inputid_1").style.backgroundColor="red";  }
    }
      

  8.   

    自己瞎写的,抛砖引玉
    function cc()
    for(var j=1; i<14; j++)
    for(var i=1; i<31; i++){
      {
      if(document.getElementById("inputid_[j]_[11]").value == "0")
       {
       document.getElementById("inputid_[j]_[i]").style.backgroundColor="red";
       }
       }
      

  9.   

    function cc()
    for(var j=1; j<31; j++)
    for(var i=1; i<14; i++){
      {
      if(document.getElementById("inputid_[j]_[11]").value == "0")
      {
      document.getElementById("inputid_[j]_[i]").style.backgroundColor="red";
      }
      }
      

  10.   

    急切需要帮助,具体问题在哪里啊?
    我根据11楼改了下,还是不行
    window.onload=color(){
      for(var i=1;j<=30;i++){
      for(var j=1;i<=13;j++){
      if(document.getElementById("input_"+j+"_11").value=0){  document.getElementById("input_"+j+"_"+i).style.backgroundColor="red";                      }
                        }
           }
     }
      

  11.   

    ok了,正确的为
      window.onload =function color()
      {
      for(var j=1;j<=31;j++){
      for(var i=1;i<=13;i++){
      var a,b; 
      a="input_"+j+"_11";
      b="input_"+j+"_"+i;  if(document.getElementById(a).value==0){  document.getElementById(b).style.backgroundColor="red";  }
      }
      }
      }