当前位置: 动力学知识库 > 问答 > 编程问答 >

Thymeleaf - if checked do something

问题描述:

I have a simple table and I have checkbox inside that table. If checkbox is selected I want to display other features.

My code:

<table>

<tr th:each="obj,iterationStatus : ${objs}">

<td th:text="${obj.name}"></td>

<td><input type="checkbox" name="firstcheckbox"></td>

<td th:if="isChecked">

<!-- do something -->

</td>

</tr>

</table>

How I do this without using javascript and backbean?

网友答案:

In this case you have two options, the first option you don't want but is not a bad option is using Javascript: creating a function called isChecked.

Otherwise, you can know if a checkbox is checked with thymeleaf in the case you are in a form which calls itself. You could do something like if(firstcheckbox != null) and, of course, your checkbox would have a value <input type="checkbox" name="firstcheckbox" value="value">. Finally, you must add as attribute in your model: model.addAttribute("firstCheckbox", firstCheckbox);

分享给朋友:
您可能感兴趣的文章:
随机阅读: