spring boot + thymeleaf 后端直接给onclick函数赋值

这里是控制器里返回的
    /**
     * @param pageUtil     分页工具类
     * @param cliCorpQuery 查询类
     * @param model        model
     * @return String
     */
    @RequestMapping(value = {"/list"}, method = RequestMethod.GET)
    public String list(PageUtil<CliCorp> pageUtil, CliCorpQuery cliCorpQuery, Model model) {
        PageUtil<CliCorp> corps;
        try {
            corps = corpClientService.queryByPage(pageUtil, cliCorpQuery);
        } catch (Exception e) {
            logger.error("queryByPage error:" + e.getMessage());
            return "queryByPage error";
        }
        model.addAttribute("corps", corps);
        return VIEW_PATH + "list";
    }


页面

 <tr th:each="corp:${corps.contents}">
                                        <td><span th:text="${corp.name}"></span></td>
                                        <td><span th:text="${corp.creditCode}"></span></td>
                                        <td><span th:text="${corp.taxNo}"></span></td>
                                        <td><span th:text="${corp.showName}"></span></td>
                                        <td><span th:text="${corp.bank}"></span></td>
                                        <td><span th:text="${corp.bankAccount}"></span></td>
                                        <td><span th:text="${corp.agent}"></span></td>
                                        <td><span th:text="${corp.address}"></span></td>
                                        <td><span th:text="${corp.status}"></span></td>
                                        <td><span th:text="${corp.creator}"></span></td>
                                        <td>
                                            <button type="button" th:οnclick="'javascript:check('+${corp.id}+',2)'">审核
                                            </button>
                                            <button type="button" th:οnclick="'javascript:check('+${corp.id}+',3)'">拒绝
                                            </button>
                                        </td>
                                    </tr>
JS

   function check(id, status) {
        $.ajax({
            type: "POST",
            data: {id: id, status: status},
            url: "/admin/corp/check",
            success: function (data) {
                if (data == "认证成功") {
                    window.location.href = ("/admin/corp/list");
                } else {
                    alert("认证失败");
                }
            },
            error: function (data) {
                alert("认证失败");
            }
        });
    }


评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值