on单击JavaScript按钮

onClick JavaScript Button

本文关键字:按钮 JavaScript 单击 on      更新时间:2023-09-26

我是JavaScript领域的新人,请帮助我解决问题

我在这里错过了什么。。。。。。。。我想纠正这个。。。。

我正在尝试:

if({!Account.CID__c}){
    window.open( '{! SUBSTITUTE($Setup.CustomSetting__c.Link__c,"[#CID#]",Account.CID__c)}');
}
else{
 window.open( '{! SUBSTITUTE($Setup.CustomSetting__c.Link__c,"[#CID#]",Account.AnotherField__C )}')
}

并得到错误:

现在它给我"意外的令牌)"错误

早些时候我有

window.open( '{!SUBSTITUTE($Setup.CustomSettings__c.Link__c,"[#CID#]",Account.CID__c)}');

我只想在这里再添加一个条件,即

If(CID__C == null){
  // put another AnotherField__C in place of that.
}else{ 
   //put Account.CID__C ...which we were having earlier 
}

在javascript中,null为false。这个语句前的运算符将反转比较(即null将变为true)。所以你可以做这样的事情。另外,请注意我是如何使用括号的。

If (!Account.CID__c) {
  //do something 
  } else {   
  //do something
}

您也可以在最后的else之前使用'else-if'语句来嵌套其他参数。

这对我很管用。。。。感谢@Ashwani

if( '{!Account.CID__c}' == 'null' || '{!Account.CID__c}' == ''){
    window.open( '{! SUBSTITUTE($Setup.CustomSetting__c.Link__c,"[#CID#]",Account.AnotherField__C)}');
}
else {
    window.open( '{! SUBSTITUTE($Setup.CustomSetting__c.Link__c,"[#CID#]",Account.CID__c )}')
}