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

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(){});

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

报告相同问题?

悬赏问题

  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)