(此代码是Adobe DC pdf文件上的javascript)
我有52行和52个带有某些参数的文本字段..并且理解代码是不可管理的...:((写的太多) 有没有可能有一个更智能的解决方案?如果我使用数组?还有其他东西吗?
var A0 = this.getField("Dropdown14.0").value
var A1 = this.getField("Dropdown14.1").value
var A2 = this.getField("Dropdown14.2").value
var A3 = this.getField("Dropdown14.3").value
.
.
.
var A52 = this.getField("Dropdown14.52").value
var J1 = this.getField("Text58").value
var num = 0;
var num1 = 0;
var al = user;
var als = users;
.
.
.
if (num!=0 && A0==" check" && A1!=" check" && A2!=" check" && A3!=" check" && A4!=" check" && A5!=" check" && A6!=" check" && A7!=" check" && A8!=" check" && A9!=" check" && A10!=" check" && A11!=" check" && A12!=" check" && A13!=" check" && A14!=" check" && A15!=" check" && A16!=" check" && A17!=" check" && A18!=" check") this.getField("Text1").value=J1+", check ("+num+")"+" "+hm+" "+"and"+" "+"("+num1+")"+" "+al+" with info :"
if (num==0 && A0==" check" && A1!=" check" && A2!=" check" && A3!=" check" && A4!=" check" && A5!=" check" && A6!=" check" && A7!=" check" && A8!=" check" && A9!=" check" && A10!=" check" && A11!=" check" && A12!=" check" && A13!=" check" && A14!=" check" && A15!=" check" && A16!=" check" && A17!=" check" && A18!=" check") this.getField("Text1").value=J1+", check ("+num1+")"+" "+al+" with info :"
if (num!=0 && A1==" check" && A2!=" check" && A3!=" check" && A4!=" check" && A5!=" check" && A6!=" check" && A7!=" check" && A8!=" check" && A9!=" check" && A10!=" check" && A11!=" check" && A12!=" check" && A13!=" check" && A14!=" check" && A15!=" check" && A16!=" check" && A17!=" check" && A18!=" check") this.getField("Text2").value=J1+", check ("+num+")"+" "+hm+" "+"and"+" "+"("+num1+")"+" "+al+" with info :"
if (num==0 && A1==" check" && A2!=" check" && A3!=" check" && A4!=" check" && A5!=" check" && A6!=" check" && A7!=" check" && A8!=" check" && A9!=" check" && A10!=" check" && A11!=" check" && A12!=" check" && A13!=" check" && A14!=" check" && A15!=" check" && A16!=" check" && A17!=" check" && A18!=" check") this.getField("Text2").value=J1+", check ("+num1+")"+" "+al+" with info :"
if (num!=0 && A2==" check" && A3!=" check" && A4!=" check" && A5!=" check" && A6!=" check" && A7!=" check" && A8!=" check" && A9!=" check" && A10!=" check" && A11!=" check" && A12!=" check" && A13!=" check" && A14!=" check" && A15!=" check" && A16!=" check" && A17!=" check" && A18!=" check") this.getField("Text3").value=J1+", check ("+num+")"+" "+hm+" "+"and"+" "+"("+num1+")"+" "+al+" with info :"
if (num==0 && A2==" check" && A3!=" check" && A4!=" check" && A5!=" check" && A6!=" check" && A7!=" check" && A8!=" check" && A9!=" check" && A10!=" check" && A11!=" check" && A12!=" check" && A13!=" check" && A14!=" check" && A15!=" check" && A16!=" check" && A17!=" check" && A18!=" check") this.getField("Text3").value=J1+", check ("+num1+")"+" "+al+" with info :"
if (num!=0 && A3==" check" && A4!=" check" && A5!=" check" && A6!=" check" && A7!=" check" && A8!=" check" && A9!=" check" && A10!=" check" && A11!=" check" && A12!=" check" && A13!=" check" && A14!=" check" && A15!=" check" && A16!=" check" && A17!=" check" && A18!=" check") this.getField("Text4").value=J1+", check ("+num+")"+" "+hm+" "+"and"+" "+"("+num1+")"+" "+al+" with info :"
if (num==0 && A3==" check" && A4!=" check" && A5!=" check" && A6!=" check" && A7!=" check" && A8!=" check" && A9!=" check" && A10!=" check" && A11!=" check" && A12!=" check" && A13!=" check" && A14!=" check" && A15!=" check" && A16!=" check" && A17!=" check" && A18!=" check") this.getField("Text4").value=J1+", check ("+num1+")"+" "+al+" with info :"
if (num!=0 && A4==" check" && A5!=" check" && A6!=" check" && A7!=" check" && A8!=" check" && A9!=" check" && A10!=" check" && A11!=" check" && A12!=" check" && A13!=" check"&& A14!=" check" && A15!=" check" && A16!=" check" && A17!=" check" && A18!=" check") this.getField("Text5").value=J1+", check ("+num+")"+" "+hm+" "+"and"+" "+"("+num1+")"+" "+al+" with info :"
if (num==0 && A4==" check" && A5!=" check" && A6!=" check" && A7!=" check" && A8!=" check" && A9!=" check" && A10!=" check" && A11!=" check" && A12!=" check" && A13!=" check" && A14!=" check" && A15!=" check" && A16!=" check" && A17!=" check" && A18!=" check") this.getField("Text5").value=J1+", check ("+num1+")"+" "+al+" with info :"
if (num!=0 && A5==" check" && A6!=" check" && A7!=" check" && A8!=" check" && A9!=" check" && A10!=" check" && A11!=" check" && A12!=" check" && A13!=" check" && A14!=" check" && A15!=" check" && A16!=" check" && A17!=" check" && A18!=" check") this.getField("Text6").value=J1+", check ("+num+")"+" "+hm+" "+"and"+" "+"("+num1+")"+" "+al+" with info :"
if (num==0 && A5==" check" && A6!=" check" && A7!=" check" && A8!=" check" && A9!=" check" && A10!=" check" && A11!=" check" && A12!=" check" && A13!=" check" && A14!=" check" && A15!=" check" && A16!=" check" && A17!=" check" && A18!=" check") this.getField("Text6").value=J1+", check ("+num1+")"+" "+al+" with info :"
if (num!=0 && A6==" check" && A7!=" check" && A8!=" check" && A9!=" check" && A10!=" check" && A11!=" check" && A12!=" check" && A13!=" check" && A14!=" check" && A15!=" check" && A16!=" check" && A17!=" check" && A18!=" check") this.getField("Text7").value=J1+", check ("+num+")"+" "+hm+" "+"and"+" "+"("+num1+")"+" "+al+" with info :"
if (num==0 && A6==" check" && A7!=" check" && A8!=" check" && A9!=" check" && A10!=" check" && A11!=" check" && A12!=" check" && A13!=" check" && A14!=" check" && A15!=" check" && A16!=" check" && A17!=" check" && A18!=" check") this.getField("Text7").value=J1+", check ("+num1+")"+" "+al+" with info :"
if (num!=0 && A7==" check" && A8!=" check" && A9!=" check" && A10!=" check" && A11!=" check" && A12!=" check" && A13!=" check" && A14!=" check" && A15!=" check" && A16!=" check" && A17!=" check" && A18!=" check") this.getField("Text8").value=J1+", check ("+num+")"+" "+hm+" "+"and"+" "+"("+num1+")"+" "+al+" with info :"
if (num==0 && A7==" check" && A8!=" check" && A9!=" check" && A10!=" check" && A11!=" check" && A12!=" check" && A13!=" check" && A14!=" check" && A15!=" check" && A16!=" check" && A17!=" check" && A18!=" check") this.getField("Text8").value=J1+", check ("+num1+")"+" "+al+" with info :"
if (num!=0 && A8==" check" && A9!=" check" && A10!=" check" && A11!=" check" && A12!=" check" && A13!=" check" && A14!=" check" && A15!=" check" && A16!=" check" && A17!=" check" && A18!=" check") this.getField("Text9").value=J1+", check ("+num+")"+" "+hm+" "+"and"+" "+"("+num1+")"+" "+al+" with info :"
if (num==0 && A8==" check" && A9!=" check" && A10!=" check" && A11!=" check" && A12!=" check" && A13!=" check" && A14!=" check" && A15!=" check" && A16!=" check" && A17!=" check" && A18!=" check") this.getField("Text9").value=J1+", check ("+num1+")"+" "+al+" with info :"
if (num!=0 && A9==" check" && A10!=" check" && A11!=" check" && A12!=" check" && A13!=" check" && A14!=" check" && A15!=" check" && A16!=" check" && A17!=" check" && A18!=" check") this.getField("Text10").value=J1+", check ("+num+")"+" "+hm+" "+"and"+" "+"("+num1+")"+" "+al+" with info :"
if (num==0 && A9==" check" && A10!=" check" && A11!=" check" && A12!=" check" && A13!=" check" && A14!=" check" && A15!=" check" && A16!=" check" && A17!=" check" && A18!=" check") this.getField("Text10").value=J1+", check ("+num1+")"+" "+al+" with info :"
if (num!=0 && A10==" check" && A11!=" check" && A12!=" check" && A13!=" check" && A14!=" check" && A15!=" check" && A16!=" check" && A17!=" check" && A18!=" check") this.getField("Text11").value=J1+", check ("+num+")"+" "+hm+" "+"and"+" "+"("+num1+")"+" "+al+" with info :"
if (num==0 && A10==" check" && A11!=" check" && A12!=" check" && A13!=" check" && A14!=" check" && A15!=" check" && A16!=" check" && A17!=" check" && A18!=" check") this.getField("Text11").value=J1+", check ("+num1+")"+" "+al+" with info :"
if (num!=0 && A11==" check" && A12!=" check" && A13!=" check" && A14!=" check" && A15!=" check" && A16!=" check" && A17!=" check" && A18!=" check") this.getField("Text12").value=J1+", check ("+num+")"+" "+hm+" "+"and"+" "+"("+num1+")"+" "+al+" with info :"
if (num==0 && A11==" check" && A12!=" check" && A13!=" check" && A14!=" check" && A15!=" check" && A16!=" check" && A17!=" check" && A18!=" check") this.getField("Text12").value=J1+", check ("+num1+")"+" "+al+" with info :"
if (num!=0 && A12==" check" && A13!=" check" && A14!=" check" && A15!=" check" && A16!=" check" && A17!=" check" && A18!=" check") this.getField("Text13").value=J1+", check ("+num+")"+" "+hm+" "+"and"+" "+"("+num1+")"+" "+al+" with info :"
if (num==0 && A12==" check" && A13!=" check" && A14!=" check" && A15!=" check" && A16!=" check" && A17!=" check" && A18!=" check") this.getField("Text13").value=J1+", check ("+num1+")"+" "+al+" with info :"
if (num!=0 && A13==" check" && A14!=" check" && A15!=" check" && A16!=" check" && A17!=" check" && A18!=" check") this.getField("Text14").value=J1+", check ("+num+")"+" "+hm+" "+"and"+" "+"("+num1+")"+" "+al+" with info :"
if (num==0 && A13==" check" && A14!=" check" && A15!=" check" && A16!=" check" && A17!=" check" && A18!=" check") this.getField("Text14").value=J1+", check ("+num1+")"+" "+al+" with info :"
if (num!=0 && A14==" check" && A15!=" check" && A16!=" check" && A17!=" check" && A18!=" check") this.getField("Text15").value=J1+", check ("+num+")"+" "+hm+" "+"and"+" "+"("+num1+")"+" "+al+" with info :"
if (num==0 && A14==" check" && A15!=" check" && A16!=" check" && A17!=" check" && A18!=" check") this.getField("Text15").value=J1+", check ("+num1+")"+" "+al+" with info :"
if (num!=0 && A15==" check" && A16!=" check" && A17!=" check" && A18!=" check") this.getField("Text16").value=J1+", check ("+num+")"+" "+hm+" "+"and"+" "+"("+num1+")"+" "+al+" with info :"
if (num==0 && A15==" check" && A16!=" check" && A17!=" check" && A18!=" check") this.getField("Text16").value=J1+", check ("+num1+")"+" "+al+" with info :"
if (num!=0 && A16==" check" && A17!=" check" && A18!=" check") this.getField("Text17").value=J1+", check ("+num+")"+" "+hm+" "+"and"+" "+"("+num1+")"+" "+al+" with info :"
if (num==0 && A16==" check" && A17!=" check" && A18!=" check") this.getField("Text17").value=J1+", check ("+num1+")"+" "+al+" with info :"
if (num!=0 && A17==" check" && A18!=" check") this.getField("Text18").value=J1+", check ("+num+")"+" "+hm+" "+"and"+" "+"("+num1+")"+" "+al+" with info :"
if (num==0 && A17==" check" && A18!=" check") this.getField("Text18").value=J1+", check ("+num1+")"+" "+al+" with info :"
if (num!=0 && A18==" check") this.getField("Text19").value=J1+", check ("+num+")"+" "+hm+" "+"and"+" "+"("+num1+")"+" "+al+" with info :"
if (num==0 && A18==" check") this.getField("Text19").value=J1+", check ("+num1+")"+" "+al+" with info :"
答案 0 :(得分:0)
您可以将值移动到数组中,并迭代该数组和子数组以进行检查。
var array = [a0, a1, a2, a3]; // add all values of a0 ... an
array.forEach((s, i, a) => {
if (num != 0 && s == "check" && a.slice(i + 1).every(t => t != "check")) {
this.getField("Text" + (i + 1)).value = J1 + ", check (" + num + ")" + " " + hm + " " + "and" + " " + "(" + num1 + ")" + " " + al + " with info :"
}
if (num == 0 && s == "check" && a.slice(i + 1).every(t => t != "check")) {
this.getField("Text1" + (i + 1)).value = J1 + ", check (" + num1 + ")" + " " + al + " with info :"
}
});