Html 在组合框中使用默认值

Html 在组合框中使用默认值,html,winforms,combobox,frontend,thymeleaf,Html,Winforms,Combobox,Frontend,Thymeleaf,我对百里香叶有问题。我有一个带有组合框和一些字段的表单。我希望在组合框中输入默认值,并且“selected”子句对我不起作用 代码如下: <select class="dsp-inline form-control" th:field="*{tipoDocumento}" required="required" th:disabled="${permisoXestion == false}"> <option value="" th:text="#{select.o

我对百里香叶有问题。我有一个带有组合框和一些字段的表单。我希望在组合框中输入默认值,并且“selected”子句对我不起作用

代码如下:

<select class="dsp-inline form-control" th:field="*{tipoDocumento}" required="required" th:disabled="${permisoXestion == false}">
      <option value="" th:text="#{select.option.default}"> </option>
      <option th:each="row : ${tipoDocumento}" th:value="${row}" th:text="#{${row.value}}" th:selected="#{${row==2}}"></option>
</select>

有人能帮我吗?

所选标签应该可以工作。请记住,它需要像
selected=“selected”
那样添加。我已经在几次选择中使用过它,而且它总是有效的。另外,在
th:each
中,您需要删除
th:selected=“#{${row==2}}”
元素,否则您的第一个选项将不是默认选项

<select class="dsp-inline form-control" required="required" th:disabled="${permisoXestion == false}">
      <option value="" th:text="#{select.option.default}"></option>
      <option th:each="row, iter : ${tipoDocumento}" th:value="${row}" th:text="#{${row.value}}" th:selected="${iter.count eq 2} ? 'selected' : 'false'"></option>
</select>

如果使用th:selected,则不能使用th:field。必须将其替换为名称属性。 那么,你能替换吗

<select class="dsp-inline form-control" th:field="*{tipoDocumento}" required="required" th:disabled="${permisoXestion == false}">


我希望默认值将是list tipoDocumento的值。那么您希望默认值作为所选值开始?或者TipodOccummento列表中的一个项目?我想要TipodOccummento列表中的一个项目如何选择默认值。提前谢谢,太好了!任何特别的值,或者我可以选择我想要的?列表第二位的值,如果可能的话。
<select class="dsp-inline form-control" th:field="*{tipoDocumento}" required="required" th:disabled="${permisoXestion == false}">
 <select class="dsp-inline form-control" name="tipoDocumento" required="required" th:disabled="${permisoXestion == false}">
th:selected="#{${row==2}}"
th:selected="${row==2}"