0

我正在 Adob​​e LiveCycle 上创建一个表格,在不同的字段中添加数字。我需要让最后一个字段(合格资产)添加所有以前的字段,但不包括其中三个的总和,一个特定的但只有当它大于 60000 时。我为第一部分编写了如下脚本(总结所有字段)这是在我命名为 TotalAssets 的字段中:

this.rawValue =Cash.rawValue+SavingsAccount.rawValue+ChildrensSavings.rawValue+CheckingAccount.rawValue+ValueHome1.rawValue+ValueHome2.rawValue+ValueVehicle1.rawValue+ValueVehicle2.rawValue+ValueVehicle3.rawValue+BusinessAccount.rawValue+BusinessAssets.rawValue+StocksBonds.rawValue+Retirement.rawValue+CDs.rawValue+OtherInvestments.rawValue+OtherAssets.rawValue;

这工作正常,但如果退休值大于 60000,则不应将其添加到计算中。这就是我写的(EligibleAssets):

if (Retirement.rawValue > 60000) {
Retirement.rawValue = 0; 
} else {
Retirement.rawValue == Retirement.rawValue ; 
}

this.rawValue = TotalAssets.rawValue - (ValueHome1.rawValue+ValueVehicle1.rawValue +Retirement.rawValue);

当我将表单另存为 PDF 时,第一个字段总数计算正确,但第二个字段显示为空白。

如果您能发现我遗漏或做错了什么,我将非常感谢任何反馈。谢谢!

4

1 回答 1

0

我在这里看到两个简单的问题。

第一个问题是您==在应该使用=.

==- 检查左侧是否等于右侧。例子:if(x == 5) {

=-左侧设置右侧的值。例子:x = 5

在第一个示例中,我们不考虑 x,但在第二个示例中,我们x 更改为 5。

所以你的代码应该是这样的:

} else {
    Retirement.rawValue = Retirement.rawValue;
}

然而,当你想到这一点时,这段代码实际上并没有做任何事情。Retirement.rawValue不会改变。

这导致我们在代码中出现第二个错误,至少在我看来它是一个错误。

if(Retirement.rawValue > 60000) {
    Retirement.rawValue = 0;
}

这实际上会发生变化 Retirement.rawValue,这可能会改变表单的 Retirement 字段中的内容。更糟糕的是,表单可能看起来相同,但在其他字段计算时表现不同,因为您更改了它的. 那将是一个非常难以捕捉的错误。rawValue

解决办法是新建一个变量:http ://www.w3schools.com/js/js_variables.asp

所以现在我们可以创建一个新变量,将该变量设置为退休金额或不设置任何内容,然后将该变量添加到rawValue末尾的其他 s 中:

var retirementOrZero;

if(Retirement.rawValue > 60000) {
    retirementOrZero = 0;
} else {
    retirementOrZero = Retirement.rawValue;
}

this.rawValue = TotalAssets.rawValue - (ValueHome1.rawValue + ValueVehicle1.rawValue + retirementOrZero);

现在我们有了一个数字,我们可以命名任何我们想要的名称,我们可以随意更改它,而不会影响除我们自己的代码之外的任何代码。因此,我们首先检查我们的退休值是否大于 60000。如果更大,我们将变量设置为 0。否则,我们将变量设置为退休值。然后我们将我们所做的变量添加到房屋和价值成本中。

作为最后一个问题,它应该做

if(Retirement.rawValue > 60000) {
    retirementValueOrZero = 0;
}

还是应该这样做

if(Retirement.rawValue > 60000) {
    retirementValueOrZero = 60000;
}

当然,如果您将其设置为 60000 而不是将其设置为零,您可能想要命名您的变量cappedRetirementValue或类似的名称——只要确保在使用它的任何地方都重命名它!

希望这会有所帮助!

编辑:你说你只有在大于 60k 时才增加退休价值,所以你想要的是:

if(RetirementValue.rawValue > 60000) {
    retirementValueOrZero = RetirementValue.rawValue;
} else {
    retirementValueOrZero = 0;
}
于 2014-07-15T19:23:48.727 回答