thymeleaf:button点击事件传递参数

<button th:data-id="${id}" type="button" class="testBtn"></button>
<script>
        $(".testBtn").click(function() {
            var id = $(this).attr("data-id");//获得参数的值
            $.ajax({
                type:'get',
                url:"/test",
                data:{id:id},
                success:function (result) {
                    if(result ==="ok"){
                        window.location.href="/main";
                    }
                }
            });
        });
</script>
原文地址:https://www.cnblogs.com/xlwq/p/12743066.html