[英]call javascript function within function
Javascript Nub。
运行一个检查5个选择框状态的函数,如果它们的值为“ Select”,我想运行一个函数以基于另一个值填充它们。 我可以在第一个函数中执行此操作,但是它会很长。
缩写版本。
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);
}
等等,
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'不是正确的命令(如果我要走了,那就长话大说吧)。 谢谢
if语句的其余部分将不会被调用,因为如果第一个命中,您将从函数返回。
if(tligc == 'Select') {
document.getElementById('otherAgency3').className = 'textBox';
return setass(3);
}
javascript中的return函数将立即返回调用函数,带值或不带值。 上面的代码基本上是说:“如果你到这一点,运行setass
以3参数的函数,并返回结果返回到调用者chek
。
如果希望方法继续执行而不结束,则需要删除此return语句。
if(tligc == 'Select') {
document.getElementById('otherAgency3').className = 'textBox';
setass(3);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.