html – 嵌入输入f.label(rails表单生成)

前端之家收集整理的这篇文章主要介绍了html – 嵌入输入f.label(rails表单生成)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想使用f.label方法创建我的表单元素标签,但是 – 我想要将表单元素嵌套在标签内。这可能吗?

– 从W3C –

To associate a label with another control implicitly,the control element must be within the contents of the LABEL element. In this case,the LABEL may only contain one control element. The label itself may be positioned before or after the associated control.

In this example,we implicitly associate two labels with two text input controls:

<form action="..." method="post">
 <p>
  <label>
     First Name
     <input type="text" name="firstname" />
  </label>
  <label>
     <input type="text" name="lastname" />
     Last Name
  </label>
  </p>
</form>

解决方法

您可以使用块将表单帮助程序嵌套在标签内。以下是使用HAML的示例,但它也适用于ERB。
= form_for your_resource do |f|
  = f.label :first_name do
    = f.text_field :first_name
原文链接:https://www.f2er.com/html/233627.html

猜你在找的HTML相关文章