-1

我正在尝试从三个字段(First、MI 和 Last)构建一个全名。如果中间的初始字段为空白,我不希望在组合名称中出现句点。我的代码在下面,当 MI 字段为空白时,名字和姓氏之间仍会出现一个句点。在这种情况下不应用 partial_name。

    // Get field values 
var F_Name = this.getField('First_Name').value; 
var M_Name = this.getField('MI').value; 
var L_Name = this.getField('Last_Name').value; 

// Build full_name string
var full_name = F_Name + " " + M_Name +  ". " + L_Name;

// Build Partial Name string
var partial_name = F_Name + " " + L_Name;
 
if(M_Name="") {event.value = partial_name;
}
else {event.value = full_name;
}

错误的屏幕截图

4

1 回答 1

-1

    // Get field values 
var F_Name = this.getField('First_Name').value; 
var M_Name = this.getField('MI').value; 
var L_Name = this.getField('Last_Name').value; 

// Build full_name string
var full_name = F_Name + " " + M_Name +  ". " + L_Name;

// Build Partial Name string
var partial_name = F_Name + " " + L_Name;
 
if(this.getField('MI').value=="") {
event.value = partial_name; 

// I think that's because you used single (=) instead of (==) or (===) and you //wrote If with a capital I 

}
else {event.value = full_name;
}

于 2018-09-28T17:34:36.867 回答