【发布时间】:2026-01-15 08:40:01
【问题描述】:
到目前为止,我已经构建了一个带有几个单选按钮和一个密码字段的表单。 现在,我想在单击相应的单选按钮后立即激活密码字段。 到目前为止,如果所有密码字段的 id 都不相同,这将起作用。
这是我目前的代码:
<form action="#" th:action="@{/passwordaenderung}" th:object="${UserCreationDto}" method="post" onsubmit="return checkPassword()">
<fieldset>
<table>
<thead>
<tr>
<th>Username</th>
<th>Password</th>
</tr>
</thead>
<tbody>
<tr th:each="user, itemStat : *{users}">
<td><input type="radio" name="radiobutton" th:value="*users[__${itemStat.index}__].username}" id="raidoButtonCheck" onclick="document.getElementById('pwd').removeAttribute('disabled')" /></td>
<td><input th:field="*users[__${itemStat.index}__].username}" disabled/></td>
<td><input type="password" name="passwordField" th:field="*{users[__${itemStat.index}__].password}" id="pwd" disabled/></td>
</tr>
</tbody>
</table>
<input type="submit" id="submitButton" th:value="Speichern">
</fieldset>
</form>
那么,它在我的浏览器中看起来像吗:
解释/编译的代码看起来像这样:
我希望有人能告诉我如何为所有密码字段获取不同的 ID,以便通过
document.getElementById('pwd').removeAttribute('disabled')
【问题讨论】:
标签: javascript html passwords thymeleaf