thymeleaf使用th:onclick()赋值后台函数

本文探讨了在使用THymeleaf时遇到的点击事件无效的问题,通过尝试不同的解决方案,最终发现使用eval函数可以成功触发后台传递的菜单url。这为处理THymeleaf中动态生成的菜单按钮点击事件提供了一种可行的方法。

在这里插入图片描述
如图,这些按钮都是通过后台传递来的权限菜单生成的按钮。
<a th:each=“menu:KaTeX parse error: Expected 'EOF', got '#' at position 20: …rdMenu}" href="#̲" class="easyui…{menu.icon}” th:text=" m e n u . n a m e " t h : o n c l i c k = {menu.name}" th:οnclick= menu.name"th:onclick={menu.url">
但这里会报500。网上搜了许多都是关于onclick传递参数的,尝试了th:οnclick="[[ m e n u . u r l ] ] " 。 显 示 结 果 为 o n c l i c k = " " a d d ( ) ” " , 点 击 无 效 。 后 来 想 起 来 j s 有 e v a l 函 数 , 改 成 t h : o n c l i c k = " e v a l ( [ [ {menu.url}]]"。显示结果为οnclick=""add()”",点击无效。 后来想起来js有eval函数,改成th:οnclick="eval([[ menu.url]]"onclick=""add()"jsevalth:onclick="eval([[{menu.url}]])"。成功了。
不知道有没有更好的方法,网上搜了好久千篇一律都是传递参数。

<!DOCTYPE html> <html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"> <head> <th:block th:include="include :: header('123456789')"/> <th:block th:include="include :: datetimepicker-css"/> <!-- <th:block th:include="include :: datetimepicker-css"/>--> <th:block th:include="include :: bootstrap-fileinput-css"/> </head> <style> </style> <body> <div> <div> <input type="text" name="filex" id="inputfile"> <div class='file-loading'> <input class='form-control file-upload' name='file' type='file' id="filex"> </div> </div> <div> <button onclick="chuli()">确定</button> </div> </div> <th:block th:include="include :: footer"/> <th:block th:include="include :: echarts-js"/> <th:block th:include="include :: datetimepicker-js"/> <th:block th:include="include :: bootstrap-fileinput-js"/> <script th:inline="javascript"> $(".file-upload").fileinput({ uploadUrl: ctx + 'common/upload', maxFileCount: 1, autoReplace: true, showPreview: false }).on('fileuploaded', function (event, data, previewId, index) { $("input[name='" + event.currentTarget.id + "']").val(data.response.url) }).on('fileremoved', function (event, id, index) { $("input[name='" + event.currentTarget.id + "']").val('') }) function chuli() { const x = document.getElementById("inputfile"); alert(x.value); } </script> </body> </html> 我使用的ruoyi框架,是bootstrap版本的,这是我的代码,我现在是通过组件打开的,我现在希望我点击确定能把我拿到的回上一个页面
09-09
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值