翻页保存已选中的复选框

function batchdel() {//批量删除
        var chk_value =[]; 
            $('input[name="ids"]:checked').each(function(){ 
                chk_value.push($(this).val());
            });
            if (chk_value.length==0) {
                alert("请选择学号!");
                return false;
            }
            if (chk_value.length > 0) {
                var msg = '确认删除' + chk_value + '吗?';
                if (confirm(msg) == true) {
                    location.href = "<%=basePath%>user/batchDelete?chk_value=" + chk_value;
                    return true;
                } else {
                    return false;
                }
            }
    }

    var checkedIds=""; //翻页保存选中的id
    function changeIds(){
        var oneches=document.getElementsByName("ids");
        for(var i=0;i<oneches.length;i++){
            if(oneches[i].checked==true){
                if(!contains(checkedIds,oneches[i].value)){
                     checkedIds+=oneches[i].value+",";
                }
             }
            if(oneches[i].checked==false){
                if(contains(checkedIds,oneches[i].value)){
            checkedIds=checkedIds.replace((oneches[i].value+","),"");
                }
             }
         }
     }
    function getChecked(){
        if(checkedIds==""){
            return;
        }
        var oneches=document.getElementsByName("ids");
        for(var i=0;i<oneches.length;i++){
            if(contains(checkedIds,oneches[i].value)){
                 oneches[i].checked="checked";
            }
         }
     }
    function contains(obj, ele) {
        if(obj==""){
            return;
        }
        var arr = obj.split(",");
        var i = arr.length;
        while (i--) {
            if (arr[i] == ele) {
                return true;  
            }  
        }  
        return false;  
    }
<a href="list?pageIndex=${pageUtil.pageIndex<pageUtil.pageCount?pageUtil.pageIndex+1:pageUtil.pageCount}" class='next' onclick="changeIds();getChecked();contains(this,obj,ele);">下一页</a>

图片描述

阅读 2.3k
2 个回答

changeIds 这方法调用了?
oneches[i].value log一下 看看有值么?

楼主,将当前页保存的 id,保存在 sessionStorage 或者 cookie 里,是可以的

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题