thymeleaf 页面a标签 onclick传参数使用方式

thymeleaf a标签onclick 传多个参数给ajax使用,用 ‘’单引号。

<a href="javascript:void(0)" th:onclick= "'javascript:goRead('+${item.id}+','+${cartoon.id}+')'"  target="_blank" th:title="${item.title}">
<script>
    function goRead( id, cartoonId){
        alert("go-read is click")
        var params = {
            username: $("#name").val(),
            phone: $("#phone").val(),
            password: $("#password").val(),
        }
        $.ajax({
                type: "post",
                url: "@{/doRegister}",
                data: JSON.stringify(params),
                dataType: 'json',
                contentType: 'application/json;charset=UTF-8',  
                success: function (r) {
                    alert(r)
                }
                })
    }   
    </script>       

猜你喜欢

转载自blog.csdn.net/fengcai0123/article/details/80911740