The check box remains selected after turning the page

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
    /**
     * 
     * @return
     */
    function changeIds(){
        var oneches=document.getElementsByName("ids");
        for(var i=0;i<oneches.length;iPP){
            if(oneches[i].checked==true){
                 //
                if(!contains(checkedIds,oneches[i].value)){
                     checkedIds+=oneches[i].value+",";
                     //console.log(oneches[i].value);
                }
             }
            if(oneches[i].checked==false){
                // idid
                if(contains(checkedIds,oneches[i].value)){
                    checkedIds=checkedIds.replace((oneches[i].value+","),"");
                }
             }
         }
     }
    /**
     * 
     * @return
     */
    function getChecked(){
        if(checkedIds==""){
            return;
        }
        var oneches=document.getElementsByName("ids");
        
        for(var i=0;i<oneches.length;iPP){
            //id
            if(contains(checkedIds,oneches[i].value)){
                 oneches[i].checked="checked";
                 //console.log(oneches[i].value);
            }
         }
     }
    /**
     * 
     * @param obj
     * @param ele
     * @return
     */
    function contains(obj, ele) {
        //console.log(obj);
        //console.log(ele);
        if(obj==""){
            return;
        }
        /*obj*/
        var arr = obj.split(",");
        //console.log(arr);
        var i = arr.length;
        while (i--) {
            if (arr[i] == ele) {
                return true;  
            }  
        }  
        return false;  
    }
    function handleClick(){
          changeIds();
          getChecked();
          contains("1","2");
        }

No error is reported. There is output in the console, but no effect is achieved

Sep.18,2021

-guess the reason and modify the answer
after flipping the page
you called the handleClick function.

function handleClick(){
    changeIds() ;
    getChecked();

}

after turning the page, the check boxes are all unchecked
handleClick function executes changeIds function

The

program walks into the condition of oneches [I]. CheckedIds = = false, so replace your checkedIds loop to an empty string

function changeIds(){
    var oneches=document.getElementsByName("ids");
    for(var i=0;i<oneches.length;iPP){
        // console.log(oneches[i].checked)
        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+","),"");
            }
         }
     }
 }

because of the for loop blocking mechanism, getChecked ()
is not executed until after the loop is executed, but the checkedIds is already an empty string.

function getChecked(){
    if(checkedIds==""){
        return;
    }
    var oneches=document.getElementsByName("ids");
    for(var i=0;i<oneches.length;iPP){
        //id
        if(contains(checkedIds,oneches[i].value)){
            oneches[i].checked="checked";
        }
    }
}

therefore, your input event should only call the changeIds function
call the getChecked function after paging


this child's foundation is too poor, don't learn, go home and raise pigs


suggest you debug this method getChecked

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1eb32da-2435.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1eb32da-2435.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?