我需要從頁面的 select 組件中獲取一個值,并將其值設定為 href 中的引數。
<td ><a th:href="@{/export(exportEntity='Person',semester='javascript:document.getElementById(\'semester\').value')}">Download</a></td>
Semeter 變數在我的服務器端具有值:
semester = javascript:document.getElementById('semester').value
而不是下拉值。
不幸的是,這段代碼沒有從 select 組件中選擇值。任何猜測我在這里做錯了什么。
uj5u.com熱心網友回復:
Thymeleaf 在服務器上運行,而 JavaScript 在瀏覽器上運行。你不能那樣混。
很難說該怎么做,因為您的問題缺乏背景關系,特別是:帶有 id 的元素是什么semester?
如果它是一個select元素(或另一個表單元素),那么可以既不使用 Thymeleaf 也不使用 JavaScript,而是使用一個簡單的表單:
<form method="get" action="/export">
<input type="hidden" name="exportEntity" value="Person">
<select name="semester">
<option value="A">Semester A</option>
<option value="B">Semester B</option>
</select>
<input type="submit" value="Download">
</form>
單擊該按鈕將使瀏覽器生成一個 URL,例如/export?exportEntity=Person&semester=A并轉到它。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/336066.html
