Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/370.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在PUG模板引擎中传递锚定标记类中的循环变量值?_Javascript_Html_Pug_Pugjs - Fatal编程技术网

Javascript 如何在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

我正在尝试使用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<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