【发布时间】:2021-04-16 11:07:30
【问题描述】:
我在 {while add this for loop in my table 下看到一条红色波浪线,我在这里缺少什么。
var cartHtml = `<table>
<tr>
<th> Item</th>
<th> Description</th>
<th> Price</th>
<th> Qty</th>
<th> Totall</th>
</tr>
<tr>`
${for (var i=0; i<5; i++){
`<td>data</td>`
}}
`</tr>
</table>`
【问题讨论】:
-
那(红色波浪线)是一个语法错误;你需要连接你正在构建的 html 字符串
-
我正在尝试用反引号来做到这一点,你能告诉我如何准确连接吗?
-
使用“+”连接
-
好吧也试试!!
-
@Wimanicesir 字符串插值不需要连接,您不能连接
${}。
标签: javascript html for-loop frontend