简体   繁体   English

多个类名不同的 div 元素可以在 jade 或其他 html 预处理器中循环吗?

[英]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>

如何使用 getElementsByClassName(<classname> ).outerHTML="" 隐藏一个<div>当 div 的 class 有多个名称时?</div><div id="text_translate"><p> 我正在尝试学习如何使用 javascript getElementsByClassName("&lt;classname&gt;").outerHTML=""在网页上隐藏&lt;div&gt;部分。</p><p> 如果我要隐藏的元素例如&lt;div class="someclassname"&gt;Some content I want to hide&lt;/div&gt; ,这一切都很好。 或者,如果使用getElementByID("&lt;divId&gt;")如果使用例如&lt;div id="somedivID"&gt; ,我会成功。</p><p> 问题是,当想要隐藏没有id的&lt;div&gt;并且为 div 的 class 列出多个名称时,如下所示:</p><pre> &lt;div class="cake forest carousel"&gt;Some content I want to hide.&lt;/div&gt;</pre><p> 如何隐藏这样一个没有 id 且没有单个 class 名称的 div?</p></div></classname> - How can I use getElementsByClassName(<classname>).outerHTML="" to hide a <div> when there are multiple names for the div's class?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 玉 - 创建多个html元素 - jade - create multiple html elements 我如何遍历 <div> python 3.7和Selenium Webdriver具有不同类名的元素? - How can I iterate through <div> elements with different class names with python 3.7 and selenium webdriver? 我如何使用 jQuery 删除除特定 class 之外的所有 div 和其他 DOM HTML 元素 - How can i remove all div's and other DOM HTML elements except a particular class using jQuery 如何在反应中的 div class='App' 之前添加多个 static html 元素? - How can I add multiple static html elements before the div class='App' in react? 如何定位 html 元素 class 名称而不是元素? - How can I target html element class names instead of elements? 将多个没有类名的html标签解析成不同的变量 - Parse multiple html tags with no class names into different variables html中不同类型的class名字 - Different types of class names in html 使用php mysql为div分配不同的类名 - Assign different class names to div with php mysql 如何使用 getElementsByClassName(<classname> ).outerHTML="" 隐藏一个<div>当 div 的 class 有多个名称时?</div><div id="text_translate"><p> 我正在尝试学习如何使用 javascript getElementsByClassName("&lt;classname&gt;").outerHTML=""在网页上隐藏&lt;div&gt;部分。</p><p> 如果我要隐藏的元素例如&lt;div class="someclassname"&gt;Some content I want to hide&lt;/div&gt; ,这一切都很好。 或者,如果使用getElementByID("&lt;divId&gt;")如果使用例如&lt;div id="somedivID"&gt; ,我会成功。</p><p> 问题是,当想要隐藏没有id的&lt;div&gt;并且为 div 的 class 列出多个名称时,如下所示:</p><pre> &lt;div class="cake forest carousel"&gt;Some content I want to hide.&lt;/div&gt;</pre><p> 如何隐藏这样一个没有 id 且没有单个 class 名称的 div?</p></div></classname> - How can I use getElementsByClassName(<classname>).outerHTML="" to hide a <div> when there are multiple names for the div's class? html div 循环时未关闭 - html div not closing when looped through
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM