【发布时间】:2020-07-15 23:48:42
【问题描述】:
我的目标是获取 javascript 函数的返回值,然后作为 spring 路径变量传递
我试着做这个代码:
-
下拉列表,填充用户想要获取的数据
<label for="cust">Select a customer</label> <select id="cust" class="form-control"> <option th:each="customer: ${customers}" th:value="${customer.id}" th:utext="${customer.name}" /> </select> -
脚本,获取选中的客户
<script> function getSelected() { var cust_id = document.getElementById("cust").value; return cust_id; }</script> -
按钮,这是我迷路的地方。如何使用 th:href 将此 cust_id 发送到我的控制器?
<input type="button" class="button form-control btn-primary" th:value="Next" onclick="getSelected()" th:href="@{/locate/{id}(id=${cust_id})}">
我的问题是如何将 cust_id 作为参数传递? 如果有最简单的方法,请告诉我如何
【问题讨论】:
标签: javascript spring thymeleaf dropdown path-variables