2017-04-20 63 views
0

这是我的第一个问题,我对它的任何不清楚的方面表示歉意。下面是我的了:如果条件为基于几个tex字段的合并文本字段

// Get field values 
var full_name = getField('Full Name').value; 
var full_name2 = getField('Full Name 2').value; 

// Build account_name string 
var account_name = full_name + " " + "and/or" + " " + full_name2; 

// Set this field's value equal to account_name 
event.value = account_name; 

它聚集两名领域进入一个用于开户形式,并增加了“和/或”。此表格用于个人账户(即一个人)和联名账户(即两人)。

我的问题:如果全名2字段为空,我可以添加什么编码来抑制/不显示“和/或”?

非常感谢您的帮助。乔

+0

这是什么语言?请*编辑您的问题*将其作为标签加入。 –

回答

0

使用ternary operator

var account_name = full_name2 ? full_name + " " + "and/or" + " " + full_name2 : full_name; 

或只使用一个if/else条件:

if (full_name2) { 
    event.value = full_name + " and/or " + full_name2; 
} else { 
    event.value = full_name; 
} 
相关问题