【问题标题】:How to add a button inside message body in Javascript?如何在 Javascript 中的消息正文中添加按钮?
【发布时间】:2019-11-27 05:24:11
【问题描述】:
我尝试过如下构建消息体-
我得到对象对象异常,如果我保留在消息正文中,它对我不起作用-
"Dear " +
$scope.emailContactinfo.name +
", \n\nPlease find attached Invoice bearing number " +
$scope.invoiceInformation.documentNo +"Paynow\n\n" +$scope.generatedUrl +
" dated " +
moment($scope.invoiceInformation.invoiceDate).format("MM-DD-YYYY") +
". \n\nThanks and Regards,\n" +
$scope.invoiceInformation.organization$_identifier +
"." + button ;`
【问题讨论】:
标签:
javascript
html
css
angularjs
angular-ui-bootstrap
【解决方案1】:
我建议使用这种格式,这样代码更具可读性 -
const button = '<button>Button</button>';
`Dear ${$scope.emailContactinfo.name}, \n\nPlease find attached Invoice bearing number ${$scope.invoiceInformation.documentNo} Paynow\n\n ${$scope.generatedUrl} dated ${ moment($scope.invoiceInformation.invoiceDate).format("MM-DD-YYYY")}. \n\nThanks and Regards,\n ${$scope.invoiceInformation.organization$_identifier}. ${button}`
【解决方案2】:
您可以在像这样的 javascript 变量中使用 html,例如:
var button = '<button>Button</button>';
var htmlBody = '<div>' + $scope.emailContactInfo + '</div>;
htmlBody += '<div>' + button + '</div>';