我正在尝试附加 <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/