Spring 将所选元素从列表组传递到ELEAF
我正在为一个项目使用Thymeleaf和Spring MVC,我正在Thymeleaf中显示一个列表,我想获取所选项目,并在按下submit时传递它们 这是我的表格和清单:Spring 将所选元素从列表组传递到ELEAF,spring,spring-mvc,thymeleaf,Spring,Spring Mvc,Thymeleaf,我正在为一个项目使用Thymeleaf和Spring MVC,我正在Thymeleaf中显示一个列表,我想获取所选项目,并在按下submit时传递它们 这是我的表格和清单: <form th:action="@{/trip-info}" th:object="${trip}" method="post"> .... <a class="list-group-item list-group-item-action" th:each="currentPerson :
<form th:action="@{/trip-info}" th:object="${trip}" method="post">
....
<a class="list-group-item list-group-item-action" th:each="currentPerson : ${trip.employees}" th:text="${currentPerson.getFirstName() + ' ' + currentPerson.getLastName()}" onclick="addPerson(this)"></a>
</form>
....
我的页面中显示了员工列表,现在我不确定是否可以将所选值传递给控制器,或者是否必须使用javascript并构造主体。有人有什么想法吗
谢谢 传输所选表单项不属于“Thymeleaf”的角色。 “Thymeleaf”是一个服务器端模板引擎,它只是用html创建代码。 客户端更改的事件(项选择)必须由JavaScript处理 举个简单的例子, 从表单提交之前,请检查javascript中的选定项,并创建一个执行提交的函数 如果您需要一个示例,请更详细地向我展示您的源代码
- 补充意见-
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<a href="http://www.stackoverflow.com" onclick="someEvent(this)">some method</a><br/>
<a href="http://www.stackoverflow.com" target="_blank" onclick="someEvent(this)">some method2</a><br/>
<a href="javascript:void(0)" target="_blank" onclick="someEvent(this)">some method3</a><br/>
<script>
function someEvent(event){
console.log(event);
}
</script>
</body>
</html>
标题
函数someEvent(事件){
console.log(事件);
}
“href”有效,但因无效(0)而无效。或按目标移动到另一个窗口选项卡。然后onclick按顺序进行
我不会说英语,解释也不成熟。很抱歉。我正在onclick事件中将我的对象传递给addPerson()函数,但没有传递