Javascript 如何在PUG模板引擎中传递锚定标记类中的循环变量值?
我正在尝试使用PUG模板引擎打印Javascript 如何在PUG模板引擎中传递锚定标记类中的循环变量值?,javascript,html,pug,pugjs,Javascript,Html,Pug,Pugjs,我正在尝试使用PUG模板引擎打印标记5次 我希望我的代码如下所示。其中我只需要两个类项和项-1,2,3等 HTML代码:所需结果 但是当我使用下面的{x}变量时,它会显示错误 - for (var x=1; x < 6; x++) a.item.item-#{x}(href='#') #{x} Item br -for(变量x=1;x
标记5次
我希望我的代码如下所示。其中我只需要两个类项和项-1,2,3等
HTML代码:所需结果
但是当我使用下面的{x}
变量时,它会显示错误
- for (var x=1; x < 6; x++)
a.item.item-#{x}(href='#') #{x} Item
br
-for(变量x=1;x<6;x++)
a、 item.item-#{x}(href='#')#{x}item
溴
错误
哈巴狗:2:17
1 |-for(变量x=1;x<6;x++)
>2 | a.item.item-#{x}(href='#')#{x}item
-----------------------^
3 | br
意外标记“interpolation”应为“text”、“interpolated code”、“code”、“slash”、“newline”或“eos”`
我知道我们使用#作为ID,但为什么它不在课堂上
项目-
之后打印-for(变量x=1;x<6;x++)
(class='item-'+x)(href='#')#{x}项
溴
代码笔:您可以这样写:
- for (var x=1; x < 6; x++)
a.item(href='#', class="item-#{x}") #{x} Item
br
-for(变量x=1;x<6;x++)
a、 item(href='#',class=“item-#{x}”)#{x}item
溴
它仍然不起作用,我再次出现错误'Pug:2:17 1 |-for(var x=1;x<6;x++)>2 | a.item.item-\\\{x}(href='.'#')#{x}item------------------^3 | br意外文本“\\{x}”请检查此处
<a class="item item-" href="#">1 Item</a><br/>
<a class="item item-" href="#">2 Item</a><br/>
<a class="item item-" href="#">3 Item</a><br/>
<a class="item item-" href="#">4 Item</a><br/>
<a class="item item-" href="#">5 Item</a><br/>
- for (var x=1; x < 6; x++)
a.item.item-#{x}(href='#') #{x} Item
br
Pug:2:17
1| - for (var x=1; x < 6; x++)
> 2| a.item.item-#{x}(href='#') #{x} Item
-----------------------^
3| br
Unexpected token `interpolation` expected `text`, `interpolated-code`, `code`, `:`, `slash`, `newline` or `eos`
- for (var x=1; x < 6; x++)
a(class='item item-'+x)(href='#') #{x} Item
br
- for (var x=1; x < 6; x++)
a.item(href='#', class="item-#{x}") #{x} Item
br