如何将 javascript return 值传递给 spring 路径变量
How to pass a javascript return value to spring path variable
我的目标是获取 javascript 函数的 return 值,然后作为 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 作为参数传递?
如果有最简单的方法,请告诉我怎么做
我也遇到过类似的情况。我是这样实现的:
$('#cust').bind('change',function() {
var custid = $(this).children("option:selected").val();
alert("You have selected the Customer with id - " + custid);
window.location = '/myAppURL?pareaName='+ $(this).val();
});
这意味着从select(选项)中选择一个值我必须将它与更改事件绑定(我使用JQuery)。不确定它是否符合您的 "exact" 要求,但希望您能理解。
我的目标是获取 javascript 函数的 return 值,然后作为 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 作为参数传递? 如果有最简单的方法,请告诉我怎么做
我也遇到过类似的情况。我是这样实现的:
$('#cust').bind('change',function() {
var custid = $(this).children("option:selected").val();
alert("You have selected the Customer with id - " + custid);
window.location = '/myAppURL?pareaName='+ $(this).val();
});
这意味着从select(选项)中选择一个值我必须将它与更改事件绑定(我使用JQuery)。不确定它是否符合您的 "exact" 要求,但希望您能理解。