html - Thymeleaf - 将 <br> 附加到输入标签

标签 html thymeleaf

我正在尝试附加 <br>在表单中的每一行输入之后,但 Thymeleaf 一直给我解析错误。

这是我遇到问题的代码片段:

<form th:if="${not #lists.isEmpty(brands)}">
<input th:each="brand : ${brands}" type="checkbox" th:value="${brand.name}" th:utext="${brand.name + <br>}" />
</form>

如果我添加 <br>输入标签之外的标签,它不会将它添加到每一行。

提前致谢

最佳答案

我认为您可能以错误的方式解决了这个问题。

th:utext 会将那个插入 <input>节点。但是,根据 HTML5 Spec<input> 什么都没有标签(“内容模型:空。”)

我想你想要更像这样的东西:

<form th:if="${not #lists.isEmpty(brands)}">
    <th:block th:each="brand : ${brands}">
        <label th:for="${#ids.next('brand')}" th:text="${brand.name}">Brand A</label>
        <input type="checkbox" th:id="${#ids.seq('brand')}"
            name="brand" th:value="${brand.name}"/>
        <br/>
    </th:block>
</form>

如果您使用的是 Spring MVC,您可能还会发现此示例很有用:http://www.thymeleaf.org/doc/tutorials/2.1/thymeleafspring.html#checkbox-fields

关于html - Thymeleaf - 将 <br> 附加到输入标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30127593/

相关文章:

jquery - 在窗口调整大小时将元素保持在同一位置

spring - 如何仅以 thymeleaf 形式传递字符串?

javascript - 将 Spring 模型属性传递给 JS 脚本

html - 向右浮动div

jquery - 基于 jquery ui slider 更改图像

javascript - 如何获得西方数字模式(用逗号分隔)

java - 如何比较变量作为字符串?

java - thymeleaf th :each filtered with th:if

html - 在纸上打印时虚点看起来不同

值更改时的 HTML 输入