我有一个小问题,我只需要重定向到 select 的值,例如:
/结果/姓名/Heli Redel
我该如何去做呢?
<div class="search">
<select th:required="true">
<option th:value="'Eha Raudreha'" th:text="'Eha Raudreha'"></option>
<option th:value="'Heli Redel'" th:text="'Heli Redel'"></option>
<option th:value="'Mait Kuusevaik'" th:text="'Mait Kuusevaik'"></option>
</select>
<a class="buttons" th:href="@{|/results/name/NAME_HERE|}"><button class="deleteBtn">Otsi</button></a><br />
</div>
最佳答案
添加一个 jQuery 函数,当单击按钮时,它会重定向到另一个 url。
jQuery(document).ready(function() {
$('.deleteBtn').on('click', function() {
var selectValue = $('.search').find('select').val()
window.location.replace("/result/name/" + selectValue);
})
})
我会向您的元素添加一些 id,以便更轻松地获取数据。
关于java - Spring , thymeleaf : redirecting to <select> value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52722985/