RT:其中form1为表单名,tians+数字 为输入文本框。
function checkT(row){
   if(row==1){
      if(form1.yfa1.value=="口服"){
          form1.tians1.readOnly=true;
          form1.tians1.style.backgroundColor = '#E8E8E8';
      }else{
          form1.tians1.readOnly=false;
          form1.tians1.style.backgroundColor = '#eff6fb';
      }
   }
   if(row==2){
      if(form1.yfa2.value=="口服"){
          form1.tians2.readOnly=true;
          form1.tians2.style.backgroundColor = '#E8E8E8';
      }else{
          form1.tians2.readOnly=false;
          form1.tians2.style.backgroundColor = '#eff6fb';
      } 
   }
   if(row==3){
       if(form1.yfa3.value=="口服"){
           form1.tians3.readOnly=true;
           form1.tians3.style.backgroundColor = '#E8E8E8';
       }else{
           form1.tians3.readOnly=false;
           form1.tians3.style.backgroundColor = '#eff6fb';
       } 
    }

解决方案 »

  1.   

    请问如何用循环处理下面这个函数?!  
    ...
    for (var i=1;i<=3 ;i++)
    {
       checkT(i); 
    }
    ...
      

  2.   

    不用循环行不?
    function checkT(row){
    var yfa = eval("form1.yfa" + row);
    var tians = eval("form1.tians" + row);
    if (typeof(yfa) != "undefined" && typeof(tians) != "undefined") { 
            if(yfa.value== "aa"){ 
                tians.readOnly=true; 
                tians.style.backgroundColor = '#E8E8E8'; 
            }else{ 
                tians.readOnly=false; 
                tians.style.backgroundColor = '#eff6fb'; 
            } 
      } 
    }
      

  3.   


    <form name="form1">
    <input type="text" name="yfa1"   value="口服"/>
    <input type="text" name="tians1"   value=""/>
    <input type="button" value=" Check " onclick="checkT('1')" />
    </form>
    <script type="text/javascript">
    <!--
    function   checkT(row){ 
                if(form1["yfa"+row].value== "口服"){ 
                        form1["tians"+row].readOnly = true; 
                        form1["tians"+row].style.backgroundColor = '#E8E8E8'; 
                }else{ 
                        form1["tians"+row].readOnly = false; 
                        form1["tians"+row].style.backgroundColor = '#eff6fb'; 
                } 
          } //-->
    </script>