Jade 中带有字符串和变量的动态元素
Dynamic element in Jade with String and a variable
我有一个名为 "elem" 的变量,"elem" 可能是头,body 和脚;
我想创建 html 元素,例如;
if elem == "body"
"t" + elem => tbody html element
if elem == "head"
"t" + elem => thead html element
if elem == "foot"
"t" + elem => tfoot element
我尝试了很多组合,但都做不到。如何实现这个案例?
尝试这样的事情(在这种情况下我假设 elem = "foot"
):
- var tag = "t" + elem;
table
thead
tbody
#{tag}
应该呈现:
<table>
<thead></thead>
<tbody></tbody>
<tfoot></tfoot>
</table>
但请记住,table 不符合 html。仅供演示。
我有一个名为 "elem" 的变量,"elem" 可能是头,body 和脚;
我想创建 html 元素,例如;
if elem == "body"
"t" + elem => tbody html element
if elem == "head"
"t" + elem => thead html element
if elem == "foot"
"t" + elem => tfoot element
我尝试了很多组合,但都做不到。如何实现这个案例?
尝试这样的事情(在这种情况下我假设 elem = "foot"
):
- var tag = "t" + elem;
table
thead
tbody
#{tag}
应该呈现:
<table>
<thead></thead>
<tbody></tbody>
<tfoot></tfoot>
</table>
但请记住,table 不符合 html。仅供演示。