Pug/Jade - input是一个自闭合元素:<input/>,但包含嵌套内容

Pug/ Jade - input is a self closing element: <input/> but contains nested content?

本文关键字:input 包含 嵌套 Jade Pug 自闭 一个 元素      更新时间:2023-09-26

我想像这样创建html:

<label class="radio-inline">
    <input type="radio" name="hidden" checked="" value="Visible"> Visible
</label>

哈巴狗/玉石:

label.radio-inline
    input(type="radio", name="hidden", value="0", checked="") Visible

但是我得到一个错误:

输入是一个自闭合元素:但包含嵌套内容。

什么意思?我该如何解决这个问题?

有多种方法可以使用Jade/Pug来做到这一点。第一种方法是使用管道字符(需要换行):

input
  | text

第二种方法是使用标签插值(您可以保持在同一行):

#[input] text

因此,叶忒罗的另一种答案是:

label.radio-inline
  #[input(type='radio', name='hidden', value=0, checked='')] Visible

请注意,您甚至可以执行以下操作:

 label #[input] text

这将产生:

<label>
  <input/> text 
</label>
你需要

这样做:

label.radio-inline
  input(type='radio', name='hidden', value=0, checked='')
  | Visible

Visibleinput放在同一行,使pupg将其解释为input元素的内部HTML。

我相信将

input放在label标签内是无稽之谈,还是不?你可以做

label(for="ya") Visible
input(id="ya", type="radio", name="hidden", value=0, checked="")

这为您提供了一个符合现代网络标准的完美标记单选按钮。