JokerRush 2019-07-30 18:01 采纳率: 0%
浏览 463
已采纳

Thymeleaf异步请求发生灵异事件?

thymeleaf进行异步请求局部刷新页面后,checkbox的事件失效。

页面截图:

图片说明

<!-- HTML-->
<td class="col-lg-1">
        <input type="checkbox" name="cacheAllRoles"/>
</td>

<!-- JS-->
<script type="text/javascript">
    // 全选\全不选 cacheAllRoles

    $("input[name='cacheAllRoles']").on("click", function () {
            if ($(this).is(':checked')) {
                    $('input[name="roleCheck"]').each(function () {
                            $(this).prop("checked", true);
                    });
            } else {
                    $('input[name="roleCheck"]').each(function () {
                            $(this).prop("checked", false);
                    });
            }
    });
</script>

页面初始化完成时,该事件是可用的;
当异步请求成功后,页面刷新完成,的事件失效。

我不知道我的问题描述的是否详细,反正就是很灵异。
前端白痴,不知道怎么排查......

补充说明:这部分是异步请求的代码

<!-- Role Table -->
<div class="col-lg-4">
<div id="roleTable" th:fragment="roleTable">
<table class="table table-striped">
<thead>
<tr>
<td class="col-lg-1">
<input type="checkbox" name="cacheAllRoles"/>
</td>
<td class="col-lg-1">ID</td>
<td class="col-lg-2" width="">角色名称</td>
<td class="col-lg-2">描述</td>
<td class="col-lg-2">配置</td>
</tr>
</thead>
<tbody>
<tr th:each="roles:${roleList}">
<td>
<input type="checkbox" th:checked="${roles.configFlag}" th:value="${roles.roleId}" name="roleCheck">
</td>
<td th:text="${roles.roleId}"></td>
<td th:text="${roles.roleName}"></td>
<td th:text="${roles.roleDescription}"></td>
<td>config</td>
</tr>
</tbody>
</table>
</div>
</div>

//获取角色列表
function configRole(userId, username) {
$("#roleTable").load("/urpCfgCtrl/getRoleListByUserId", {"userId": userId});
}
  • 写回答

1条回答

  • space1103 2019-07-31 09:55
    关注

    我现在猜想有可能是因为你的$("input[name='cacheAllRoles']")这个是动态创建出来的,所以绑定事件需要用$("body").on("click","input[name='cacheAllRoles']",function(){});

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗
  • ¥15 钢筋实图交点识别,机器视觉代码
  • ¥15 如何在Linux系统中,但是在window系统上idea里面可以正常运行?(相关搜索:jar包)
  • ¥50 400g qsfp 光模块iphy方案
  • ¥15 两块ADC0804用proteus仿真时,出现异常