【发布时间】:2022-01-01 21:29:23
【问题描述】:
我使用 Thymeleaf 创建了一个表单。此表单包含一个文本字段和一个标签。但是 Thymeleaf 没有为标签的for 属性分配正确的 id(或者实际上它为文本字段分配了错误的 id)。
这是模板:
<form action="#" th:action="@{/test}" th:object="${nameBean}" method="post">
<div class="form-group" th:classappend="${#fields.hasErrors('name')}? has-error">
<label class="control-label" th:for="${#ids.next('name')}">Name</label>
<input type="text" class="form-control" placeholder="Enter your name" th:field="*{name}" />
</div>
<button type="submit" class="btn btn-default">Send</button>
</form>
这是生成的 HTML:
<form action="/test" method="post">
<div class="form-group">
<label class="control-label" for="name1">Name</label>
<input type="text" class="form-control" placeholder="Enter your name" id="name" name="name" value="">
</div>
<button type="submit" class="btn btn-default">Send</button>
</form>
根据 Thymeleaf 指南,for 属性应该是正确的,但文本字段的 id 应该附加一个数字。为什么没有附加这个数字?
【问题讨论】:
标签: thymeleaf