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

瘦欲@ 提交于 2019-12-01 15:32:32

There are multiple ways to do that using Jade / Pug. The first way is to use a pipe char (which requires a new line):

input
  | text

The second way is to use tag interpolation (and you can stay on the same line):

#[input] text

So an alternative Jethro's answer would be:

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

Note that you can even do:

 label #[input] text

Which will generate:

<label>
  <input/> text 
</label>

You'll need to it like this:

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

Putting Visible on the same line as input, makes pug interpret it as the inner HTML of the input element.

I believe it's nonsense to put the input inside the label tag, or no? You could just do

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

That gives you a perfectly labeled radio button in accord with modern web standards.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!