日期:2014-05-16  浏览次数:20352 次

使用json临时保存信息,并分页。复选框选中和为选择的功能及临时保存信息
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
<body>
<div>
<table border="1" id="table_grid">
<tr><td><input type="checkbox" onclick/></td><td>ID</td><td>Name</td></tr>
</table>
<div><a href="javascript:createGrid('pre')">pre</a>   <a href="javascript:createGrid('next')">next</a>    <a href="javascript:getList()">save</a></div>
</div>


<div id="div_update">
<table border="1" id="table_update">
<tr><td>ID</td><td>Name</td></tr>
</table>
<div><a href="javascript:createUpdateGrid('pre','1')">pre</a>    <a href="javascript:createUpdateGrid('next','1')">next</a>    <a href="">update</a></div>
</div>

</body>
</html>
<script src="jquery-1.4.2.js" type="text/javascript"></script>
<script type="text/javascript">

    var currentPage = 1; //当前页数

    var currentPageUpdate = 1;//update当前页数

    var objList = new Array(); //用于存放选中的复选框ID

    var updateObjList = new Array();//用于存放勾选框选中的对象
   
    //模拟数据源,第一页数据
    var source1 = [{ id: 1, name: "beny" }, { id: 2, name: "beny" }, { id: 3, name: "beny" }, { id: 4, name: "beny" }, { id: 5, name: "beny"}];

    //模拟数据源,第二页数据
    var source2 = [{ id: 6, name: "ben" }, { id: 7, name: "ben" }, { id: 8, name: "ben" }, { id: 9, name: "ben" }, { id: 10, name: "ben"}];

    //模拟数据源update,第一页数据
    var sourceUpdate1 = [{ id: 1, name: "aa1" }, { id: 2, name: "aa2" }, { id: 3, name: "aa3" }, { id: 4, name: "aa4" }, { id: 5, name: "aa5"}];

    //模拟数据源update,第二页数据
    var sourceUpdate2 = [{ id: 6, name: "bb" }, { id: 7, name: "bb" }, { id: 8, name: "bb" }, { id: 9, name: "bb" }, { id: 10, name: "bb"}];
   
    createGrid("pre");//首次创建表格

    //创建表格
    function createGrid(page) {
        delRow("table_grid");
        var source;
        if (page == "pre") {//模拟分页1
            source = source1;
            currentPage = 1;
        }
        else {//模拟分页2
            source = source2
            currentPage = 2; ;
        }
        var table = document.getElementById("table_grid");
        for (var i = 0; i < source.length; i++) {
            var tr = table.insertRow();

            var tdCkb = tr.insertCell();
            tdCkb.innerHTML = "<input type='checkbox' name='ckb' id='" + source[i].id + "' oncl