[英]Can multiple div elements with different class names be looped in jade or other html preprocessors?
A list of different div elements with same class name can be written briefly with the help of jade preprocessor like :在玉预处理器的帮助下,可以简单地编写具有相同类名的不同 div 元素的列表,例如:
-var num = 4 while num-- .c
which is equivalent to in html :这相当于在 html 中:
<div class="c"> </div> <div class="c"> </div> <div class="c"> </div> <div class="c"> </div>
Is there any way to generate the list of different div elements with different class names with the help of some other loop functions in Jade or Haml or Markdown or Slim or any other html preprocessor.有什么方法可以在 Jade 或 Haml 或 Markdown 或 Slim 或任何其他 html 预处理器中的其他一些循环函数的帮助下生成具有不同类名的不同 div 元素的列表。
<div class="c1"> </div> <div class="c2"> </div> <div class="c3"> </div> <div class="c4"> </div>
Yes.是的。 In Jade you could do it like this:在 Jade 中,你可以这样做:
- var num=1
while num <= 4
div(class="c#{num++}")
Or you could put your classnames in an array and do it like this:或者你可以把你的类名放在一个数组中,然后这样做:
- var arr = ['c1','c2','c3','c4']
each i in arr
div(class=i)
Both ways will give you the output of:两种方式都会为您提供以下输出:
<div class="c1"> </div>
<div class="c2"> </div>
<div class="c3"> </div>
<div class="c4"> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.