胸腺-附加< br>输入标签 [英] Thymeleaf - Appending <br> to input tag
问题描述
我正在尝试在表单中的每个输入行之后添加一个&br; br>
,但是Thymeleaf不断给我带来解析错误.
I'm trying to append a <br>
after every input line in a form, but Thymeleaf keeps giving me parsing error.
以下是我遇到问题的代码段:
Here is the code piece that I'm having trouble with:
<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>
标记添加到输入标记之外,则不会将其添加到每一行.
If I add the <br>
tag outside of input tag, it doesn't add it to each line.
预先感谢
推荐答案
我认为您可能会以错误的方式进行操作.
I think you may be going about this in the wrong way.
th:utext
会在< input>
节点内的 中插入该代码.但是,根据 HTML5规范,没有任何结果< input>
标记(内容模型:空".)
th:utext
would insert that within the <input>
node. But, according to the HTML5 Spec, nothing goes in an <input>
tag ("Content model: Empty.")
我认为您想要更多类似这样的东西:
I think you want something more like this:
<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
If you're using Spring MVC, you may also find this example helpful: http://www.thymeleaf.org/doc/tutorials/2.1/thymeleafspring.html#checkbox-fields
这篇关于胸腺-附加< br>输入标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!