1.table的html
<table id="tableId"  class="table table-bordered">
                            <thead>
                            <tr>
                                <th>
                                    <label class="lyear-checkbox checkbox-primary">
                                        <input type="checkbox" id="check-all"><span></span>
                                    </label>
                                </th>
                                <th>编号</th>
                                <th>用户名</th>
                                <th>性别</th>
                                <th>账号状态</th>
                                <th>创建者</th>
                                <th>修改者</th>
                                <th>角色</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>

                           <c:forEach items="${pageList}" var="user" >
                            <tr>
                                <td>
                                    <label class="lyear-checkbox checkbox-primary">
                                        <input class="getAllId" type="checkbox" name="ids[]" value="${user.id}"><span></span>
                                    </label>
                                </td>
                                <td>${user.id}</td>
                                <td>${user.username}</td>
                                <c:if test="${user.gender == 1}">
                                    <td></td>
                                </c:if>
                                <c:if test="${user.gender == 0}">
                                    <td></td>
                                </c:if>
                                <c:if test="${user.state == 0}">
                                    <td><span class="text-success">正常</span></td>
                                </c:if>
                                <c:if test="${user.state == 1}">
                                    <td><span class="text-danger">封禁</span></td>
                                </c:if>
                                <td>${user.createBy}</td>
                                <td>${user.modifyBy}</td>
                                <td>
                                  <c:forEach items="${user.roles}" var="role">
                                      <span class="btn-primary">${role.name}</span>
                                  </c:forEach>
                                </td>
                                <td style="width: 500px">
                                    <div class="btn-group">
                                        <button data-target="#edit" data-toggle="modal" data-userId="${user.id}" data-whatever="@mdo" class="btn btn-success btn-w-sm">编辑</button>
                                        <button style="margin-left: 20px" data-toggle="modal" data-id="${user.id}" data-target="#exampleModal" data-whatever="@mdo" class="btn btn-info btn-w-sm">授权角色</button>
                                        <button style="margin-left: 20px" data-id="${user.id}" data-name="${user.username}" class="example-p-2 btn btn-danger btn-w-sm">删除</button>
                                    </div>
                                </td>
                            </tr>

                           </c:forEach>

                            </tbody>
                        </table>
2.点击多选框获取出用户id(checkbox被选中后length>0)
$('.getAllId').click(function (){
       let res = $('#tableId tr')
       let arr = []
       res.each(function (index, item){
           $(this).children('td:first').each(function (j, item1){
               let checkbox = $(this).find(':checkbox:checked');
               if (checkbox.length > 0){
                   let userid1 = checkbox.val()
                   arr.push(userid1)
               }
           })
       })
       u_ids = arr
   })

在这里插入图片描述

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐