html - 使用 Thymeleaf 在 Select 上选择选项后如何执行操作?
问题描述
使用 Thymeleaf 在 Select 上选择选项时,我试图重定向我的页面。我的代码是这样写的:
<select>
<option th:each="size : ${pageSizes}" th:text=${size} th:onclick="'window.location.href = \'' + @{/ingredient(size=${size})} + '\''"></option>
</select>
而且,在谷歌浏览器上检查后,创建的 HTML 是:
<select>
<option onclick="window.location.href = '/ingredient?size=5'">5</option>
<option onclick="window.location.href = '/ingredient?size=10'">10</option>
<option onclick="window.location.href = '/ingredient?size=20'">20</option>
<option onclick="window.location.href = '/ingredient?size=25'">25</option>
<option onclick="window.location.href = '/ingredient?size=50'">50</option>
</select>
But nothing happens when a select a new Option. 我究竟做错了什么?
解决方案
在标签上使用 onchange 事件select
而不是 onclick。
<select th:onchange="'window.location.href = \'' + @{/ingredient} + '?size=\' + this.value ' ">
<option th:each="size : ${pageSizes}" th:text=${size} ></option>
</select>
推荐阅读
- acumatica - 自定义屏幕上的新操作定义
- python - 傅里叶变换 (FFT) 的 3 个正弦曲线图
- python - 如何使用 random 模块打印两个随机字符串?
- r - Neuralnet 仅在 R 中打印图的下半部分
- ruby-on-rails - Rails 测试从控制器调用该方法
- linux - 在我的 shell 脚本中,我想列出当前目录中的所有文件
- angular - Angular ngFor let x in y 显示数组中长度的附加元素
- arrays - 我如何在 Kotlin 中使用 ListOfArrays
- python - 如何使用 python 获取完整的图像 url
- filter - 创建调整另一个筛选器的 Tableau 筛选器