Javascript &引用;如果&引用;否则";带有语法错误的语句

Javascript &引用;如果&引用;否则";带有语法错误的语句,javascript,if-statement,syntax,Javascript,If Statement,Syntax,在第11、12、13行出现以下代码语法错误 // Get the field values var DP = +getField("DESIGN_Projection").value; var TC = +getField("ASBUILT_Top_of_Concrete").value; var GE = +getField("ASBUILT_Ground_Elevation").value; // If DP is N/A, set this field to display N/A

在第11、12、13行出现以下代码语法错误

// Get the field values
var DP = +getField("DESIGN_Projection").value;
var TC = +getField("ASBUILT_Top_of_Concrete").value;
var GE = +getField("ASBUILT_Ground_Elevation").value;



// If DP is N/A, set this field to display N/A
If (DP === N/A); {
    event.value = "NA";  // display N/A in this field
} else 
{
    //...otherwise, set this field value to the result of the following calculation
    event.value = ((TC - GE) * 1000);    
}

If
应为
If
(小写i)

同时删除
来自if

if (DP === N/A) {
    event.value = "NA";  // display N/A in this field
} else 

if语句末尾有一个分号


如果
也应该是小写的

这行有几个问题:

If (DP === N/A); {
首先,请注意,
If
应为小写(
If
)。其次,请注意,
if
语句后面有一个分号。这使语言认为您的代码应该被解释为

If (DP === N/A)
   ;  // Do nothing

{
    event.value = "NA";  // display N/A in this field
} else 
{
    //...otherwise, set this field value to the result of the following calculation
    event.value = ((TC - GE) * 1000);    
}
从这一点上,应该可以更清楚地知道错误是什么-有一个神秘的
else
漂浮在周围

如果删除分号并将
If
更改为
If
,则错误应消失


希望这有帮助

这不是java,是吗?if语句的基本设置就是“if(){something;}”