How to pass variables into an HTML body

前端 未结 2 1391
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-24 06:07

I have created this script that allows me to select a certain food item and the serving size and then it calculates nutritional value, adds it to a database, sums it all at the

2条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-24 07:00

    The HTML must be a string (text), and you need to build the HTML with a text formula. Text strings in JavaScript are put together, (concatenated) with a plus sign:

    var tableHTML = '' + //Note single quotes on ends
       "" +
       "" +
       "" +
       "
    Calories" + calories + "
    Calories From Fat" + caloriesFromFat + "
    PolyUnsaturated" + polyFat + "
    ";

    If double quotes are used in the HTML attribute, then use single quotes on the ends of the string. Then just use the variable name for the email HTML:

    htmlBody: tableHTML
    

提交回复
热议问题