尝试自学javascript我可以自己做一些小脚本,但这个让我难过。我已经尝试了几个星期,无法到达任何地方。example image
我的目标是让标有结束项目的字段自动填充列表中填写的最后一项。
我知道如何在excel中执行此操作,但使用javascript我完全失去任何指导将非常感谢提前感谢。
我之前尝试过这个:
var one = this.getField("a1");
var two = this.getField("a2");
var three = this.getField("a3");
//for all 25 fields
if(two.value==''||two.value==null){
this.getField("a1")}
else if (three.value==''||three.value==null){
this.getField("a2")}
//for all 25 fields
答案 0 :(得分:1)
下面显示的循环遍历所有字段。只要它找到一个值,它就会记住该值(所以" theResult"总是包含当前最后找到的项目)。如果没有找到任何值(换句话说,如果我们找到列表中的最后一项,我们只需打破并知道" theResult"包含最后一个实际值。
// Start by not having any result
var theResult = null;
// Loop over all fields
for (var theIndex = 1; theIndex < 26; theIndex++) {
// get this field
var theField = this.getField( "a" + theIndex );
// If this field has a value, take it, if not quit our loop
if (theField.value) {
theResult = theField.value;
} else {
break;
}
}