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
})