JavaScript 在 thymeleaf 中不起作用。
在 Spring Boot Thymeleaf 中,首先可以打开模态。但第二、第三……东西无法打开模态。
每个事物都有类名,但只有第一个事物可以打开模态。
我认为 JavaScript 只能做第一件事,而不能做其他事情。
<tr th:each="board, i : ${boards}">
<th scope="row" th:text="${i.count}">1</th>
<td>
<p class="show" th:text="${board.title}">Title</p>
<div class="modal"> .... </modal>
</td>
<td th:text="${board.writer}">Son</td>
<td th:text="${board.createDate}">2022-02-01</td></p>
</tr>
js
function show() {
document.querySelector(".background").className = "background show";
}
function close() {
document.querySelector(".background").className = "background";
}
document.querySelector(".show").addEventListener("click", show);
document.querySelector(".close").addEventListener("click", close);
请帮我
使用您的代码,您只需将事件侦听器添加到第一个元素班级的".show"
。您应该向类的所有成员添加事件侦听器。以下代码应该完成这项工作:
document.querySelectorAll('.show').forEach(item => {
item.addEventListener('click', show);
})
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)