正确的Thymeleaf中th:each嵌套th:onclick的方法

最近使用Thymeleaf,想实现th:each嵌套th:onclick,把遍历中的对象的值传入onclick方法;

网上找了一堆方法,总是不能用;然后自己又多次尝试,终于找到能用的方法了。

以下方法亲测绝对可用,onclick中可字母可数字。

代码如下:

<table style="text-align: center; margin-top: 100px; padding: 10px 30px; background-color: white;">
        <tr>
            <td colspan="6">列表页</td>
        </tr>
        <tr>
            <td>ID</td>
            <td>姓名</td>
            <td>地址</td>
            <td>电话</td>
            <td colspan="2"><a href="javascript:void(0)" onclick="insertFuction()">新增</a></td>
        </tr>
        <tr th:each="item : ${list}">

                <td th:text="${item.id}"></td>
                <td th:text="${item.name}"></td>
                <td th:text="${item.address}"></td>
                <td th:text="${item.phone}"></td>
                <td><a href="javascript:void(0)" th:onclick="updateFuction('[(${item.id})]','[(${item.name})]','[(${item.address})]','[(${item.phone})]')">编辑</a></td>
                <td><a href="javascript:void(0)" th:onclick="deleteFuction('[(${item.id})]')">删除</a></td>

        </tr>
</table>

顺便发下script(这个不看也行):

<script>
function updateFuction(mid,name,address,phone) {
         //通过日志可以查看传入的参数是否正确
         console.log(mid);
         console.log(name);
         console.log(address);
         console.log(phone);
         //省略update请求部分
}
</script>

 

  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

追逐梦想永不停

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值