我试图<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>
Run Code Online (Sandbox Code Playgroud)
如果我将<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>
Run Code Online (Sandbox Code Playgroud)
如果您使用的是Spring MVC,则该示例也可能会有所帮助:http : //www.thymeleaf.org/doc/tutorials/2.1/thymeleafspring.html#checkbox-fields