Javascript 小块。
运行一个检查 5 个选择框状态的函数,如果它们的值为“选择”,我想运行一个函数来根据另一个值填充它们。我可以在第一个函数中做到这一点,但它会变得很长。
缩略版。
function chek{
var tligc = document.getElementById('assigc').innerHTML;   
var tligd = document.getElementById('assigd').innerHTML;
 if(tligc == 'Select'){document.getElementById('otherAgency3').className = 'textBox';
    return setass(3);
       }      
if(tligd == 'Select'){document.getElementById('otherAgency4').className = 'textBox'
 return setass(4);
}
ETC,
function setass(value){  
    var KaRa = document.getElementById('assig').innerHTML;
                           if(KaRa =='Planning Officer'){
 document.getElementById('otherAgency'+[value]).options.length=0
 document.getElementById('otherAgency'+[value]).options[0]=new Option("Select", "Select", true, false)  
 document.getElementById('otherAgency'+[value]).options[1]=new Option("Situation Unit", "Situation Unit", true, false)
 document.getElementById('otherAgency'+[value]).options[2]=new Option("Management Support", "Management Support", true, false)  
         return  }
else if(KaRa =='Operations Officer'){
 document.getElementById('otherAgency'+[value]).options.length=0
 document.getElementById('otherAgency'+[value]).options[0]=new Option("Select", "Select", true, false)  
 document.getElementById('otherAgency'+[value]).options[1]=new Option("Staging Area Manager", "Staging Area Manager", true, false)
    return }
else if(KaRa =='Logistics Officer'){
 document.getElementById('otherAgency'+[value]).options.length=0
 document.getElementById('otherAgency'+[value]).options[0]=new Option("Select", "Select", true, false)  
 document.getElementById('otherAgency'+[value]).options[1]=new Option("Supply Unit", "Supply Unit", true, false)
 document.getElementById('otherAgency'+[value]).options[2]=new Option("Communications Support", "Communications Support", true, false)  
 document.getElementById('otherAgency'+[value]).options[3]=new Option("Facilities Unit", "Facilities Unit", true, false)
        return }
    else{document.getElementById('otherAgency'+[value]).options.length=0;
      return }
       }
 }    
它填充了第一个选项,但没有为剩余的 if 测试运行检查函数的其余部分,关于如何运行函数 setass 的任何指针,然后在正确的点再次返回到主函数?我假设'return'不是正确的命令(如果我离开了,只是说并且我会做很长的路)。谢谢