checkbox分页多选

分页checkbox选中在刷新页面时候会失效,思路是把选中的再一页时放入查询的controller中,再传回前台。

<input id="settleNoList" name="settleNoList" type="hidden" value="${(condition.settleNoList)!''}" />

JS部分

$(function () {
    checkedNos = $("#settleNoList").val();
    paymentIds= "";
$("input[name=ke]").click(function(){
    if(this.checked==true){
        var pay="pay"+this.value;
        //避免重复添加(若存在元素时,不添加)
        if(!contains(checkedNos,this.value)){
            checkedNos+=this.value+",";
            paymentIds +=pay+",";
        }
    } else {
        var pay="pay"+this.value;
        if(contains(checkedNos,this.value)){
            checkedNos=checkedNos.replace((this.value+","),"");
            paymentIds =paymentIds.replace((pay+","),"");
        }
    }
    $("#settleNoList").val(checkedNos);
});

------------------------------------------------------

function contains(obj, ele) {
    if(obj=="" || obj.indexOf(",") < 0){
        return;
    }
    var arr = obj.split(",");
    var i = arr.length;
    while (i--) {
        if (arr[i] == ele) {
            return true;
        }
    }
    return false;
}

-----------------------------

页面初始化的时候

//初始化checkbox
window.onload=function (){
    var selected=subStrAarry(checkedNos);
    $("input[name=ke]").each(function () {
        if (isInArray(selected,this.value)){
            var pay="pay"+this.value;
            changeValueByName(pay);
            this.checked = true;
        }
    });
};
function isInArray(arr,value){
    for(var i = 0; i < arr.length; i++){
        if(value === arr[i]){
            return true;
        }
    }
    return false;
}



猜你喜欢

转载自blog.csdn.net/ws346348183/article/details/81026109