假如数据有五页,当前页面是第三页,我怎么获取第三页所有数据的学生id
通过元素id或name循环获取每行数据的id呗
肯定需要你前端传id啊
<td><input type="checkbox" id="box_${stat.index}" value="${user.userId}"></td>
<script type="text/javascript">
$(function(){
/** 获取上一次选中的部门数据 */
var boxs = $("input[type='checkbox'][id^='box_']");
$("#checkAll").click(function(){
// this是checkAll this.checked是true
// 所有数据行的选中状态与全选的状态一致
boxs.attr("checked",this.checked);
})
/** 给数据行绑定鼠标覆盖以及鼠标移开事件 */
$("tr[id^='data_']").hover(function(){
$(this).css("backgroundColor","#eeccff");
},function(){
$(this).css("backgroundColor","#ffffff");
})
/** 删除员工绑定点击事件 */
$("#delete").click(function(){
/** 获取到用户选中的复选框 */
var checkedBoxs = boxs.filter(":checked");
if(checkedBoxs.length < 1){
$.ligerDialog.error("请选择一个需要删除的用户!");
}else{
/** 得到用户选中的所有的需要删除的ids */
var ids = checkedBoxs.map(function(){
return this.value;
})
$.ligerDialog.confirm("确认要删除吗?","删除用户",function(r){
if(r){
// alert("删除:"+ids.get());
// 发送请求
window.location = "${pageContext.request.contextPath}/userDelete/" + ids.get();
}
});
}
})
})
</script>
复选框选择获取id以逗号","隔开的字符串
前端可以隐藏一个input标签,在其中放入后台传入前端的id,当需要传至后台时,循环选中的数据行,获取id,传至后台.
全选的复选框:
<input type='checkbox' onclick='checkAll(this);' sog='all'/>
每条数据的复选框:
<input type='checkbox' class='all' id='1' value='1'/>
checkAll代码:
function checkAll(that) {
//如果是选中状态
var sog = $(that).attr("sog");
if($(that).prop("checked")==true){
$("."+sog).prop('checked',true);
}
if($(that).prop("checked")==false){
$("."+sog).prop('checked',false);
}
}
ajax post的data处理:
var obj = $(".all");
var check_val = [];
for(var k in obj){
if(obj[k].checked)
check_val.push(obj[k].value);
}
var openIds=check_val.join(',');