3

checkbox选中并记住状态(分页)

 2 years ago
source link: https://www.oschina.net/question/5422677_2324088
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

checkbox选中并记住状态(分页)

天黑了啊 发布于 今天 14:57
var checkedIds= [];//保存选中的id,亦适用于分页

        /* 将选中的数据ID保存*/
        $(function () {
            $(".dfinput1").click(function() {
                if ($(this).is(":checked")) {
                    checkedIds.push($(this).attr("id"));
                } else {
                    for (var i = 0; i < checkedIds.length; i++) {
                        if ($(this).attr("id") == checkedIds[i]) {
                            checkedIds.splice(i, 1);
                            break;
                        }
                    }
                }
            })
        })


        //翻页后设置是否选中
        function setChecked(){
            console.log(checkedIds)
            var boxes = $(".dfinput1");
            console.log(boxes)
            for(var i=0;i<boxes.length;i++){
                var id = boxes[i].id;
                console.log(id)
                console.log(checkedIds.indexOf(id,0)!=-1)
                if(checkedIds.indexOf(id,0)!=-1){
                    boxes[i].checked = true;
                }else{
                    boxes[i].checked = false;
                }
            }
        }
<table class="tablelist">
                <thead>
                <tr>
                    <th>课程编号</th>
                    <th>课程名称</th>
                    <th><input type="checkbox" class="dfinput-all">全选</th>
                </tr>
                </thead>
                <tbody>
                <s:iterator value="pageResult1.data">
                    <tr>
                        <td>${curriculumId}</td>
                        <td>${courseName}</td>
                        <td><input name="curriculumId" id="curriculumId_${curriculumId}" type="checkbox" class="dfinput1" value="${curriculumId}"></td>
                    </tr>
                </s:iterator>
                </tbody>
            </table>

up-96fb1d703e9b65953f8abd3673e8550dbd2.png

获取到id了,但是上一页勾选了,到了下一页保存的时候,上一页的并没有保存成功。

有没有大佬会的,求救!!!


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK