繁体   English   中英

Thymeleaf-追加 <br> 输入标签

[英]Thymeleaf - Appending <br> to input tag

我正在尝试在表单中的每个输入行之后附加一个<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规范<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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM