软件开发定制定制jQuery实现表单的增删改查(完整版)

软件开发定制定制实现表单的增删改查

html代码

<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <meta http-equiv="X-UA-Compatible" content="IE=edge">    <meta name="viewport" content="width=device-width, initial-scale=1.0">    <title>Document</title>    <link rel="stylesheet" href="./font-awesome-4.7.0/css/font-awesome.min.css">    <style>        * {            margin: 0;            padding: 0;        }        .wrapper {            box-sizing: border-box;            position: relative;            width: 1349px;            margin: 0 auto;            padding-left: 175px;        }        .wrapper .add {            width: 110px;            line-height: 35px;            border-radius: 8px;            background-color: #327AB7;            color: #fff;            /* font-size: 18px;            font-weight: bold; */            text-align: center;        }        .top {            margin-top: 10px;        }        .top input {            line-height: 35px;        }        .top button {            line-height: 35px;            width: 80px;            background-color: #327AB7;            color: #fff;            border: none;            outline: none;            border-radius: 5px;        }        table tr {            width: 1000px;            text-align: left;            border-bottom: 1px solid lightgray;            /* background-color: #F9F9F9; */        }        th,        td {            width: 250px;            line-height: 50px;            float: left;            border-bottom: 1px solid lightgray;        }        tr span {            display: inline-block;            width: 60px;            line-height: 25px;            text-align: center;            color: #fff;            border-radius: 3px;            font-size: 14px;            margin-right: 10px;        }        tr .update {            background-color: #5CB75C;        }        tr .del {            background-color: #D9534F;        }        .bg1,        .bg2 {            position: absolute;            left: 0;            top: 0;            width: 100%;            height: 100vh;            background-color: rgba(0, 0, 0, 0.5);            display: none;        }        .addList,        .updateList {            position: relative;            z-index: 100;            /* top: 200px;            left: 200px;  */            width: 400px;            height: 230px;            border: 1px solid gray;            border-radius: 5px;            /* display: none; */            background-color: #fff;            margin-left: 450px;            margin-top: 200px;            z-index: 100;        }        .addList input,        .updateList input {            /* outline: none; */            width: 380px;            line-height: 25px;            margin-top: 20px;            margin-left: 8px;            outline: skyblue;            /* border-radius: 3px; */            /* margin: 0 auto; */        }        .addList .title,        .updateList .title {            margin-top: 10px;            padding-left: 10px;            padding-bottom: 20px;            border-bottom: 1px solid lightgray;        }        .addList .btn,        .updateList .btn {            text-align: right;            margin-top: 10px;            padding-top: 10px;            padding-right: 10px;            border-top: 1px solid lightgray;            font-size: 14px;        }        .addList .btn .close,        .updateList .btn .close {            display: inline-block;            width: 50px;            line-height: 30px;            text-align: center;            border-radius: 2px;            border: 1px solid gray;        }        .addList .btn .qr,        .updateList .btn .qr {            display: inline-block;            width: 80px;            line-height: 30px;            text-align: center;            border-radius: 2px;            border: 1px solid gray;            background-color: #327AB7;            color: #fff;        }    </style></head><body>    <div class="wrapper">        <div class="add">            <i class="fa fa-plus"></i><span>添加记录</span>        </div>        <div class="top">            <input type="text" placeholder="软件开发定制定制软件开发定制定制请输入用户名">            <button><i class="fa fa-search" aria-hidden="true"></i><span>查询</span></button>        </div>        <table border="0">            <tr class="first">                <th>id</th>                <th>username</th>                <th>password</th>                <th>操作</th>            </tr>            <!-- <tr>                <td>1</td>                <td>张三</td>                <td>123456</td>                <td><span class="update"><i class="fa fa-pencil" aria-hidden="true"></i>修改</span><span class="del"><i                            class="fa fa-trash" aria-hidden="true"></i>删除</span></td>            </tr> -->        </table>        <div class="bg1">            <div class="addList">                <div class="title">                    添加记录                </div>                <div class="username">                    <input type="text" placeholder="请输入用户名">                </div>                <div class="pwd">                    <input type="password" placeholder="软件开发定制定制请输入密码">                </div>                <div class="btn">                    <span class="close">关闭</span>                    <span class="qr">确认添加</span>                </div>            </div>        </div>        <div class="bg2">            <div class="updateList">                <div class="title">                    修改记录                </div>                <input type="hidden" class="hidden">                <div class="username">                    <input type="text" placeholder="请输入用户名">                </div>                <div class="pwd">                    <input type="password" placeholder="请输入密码">                </div>                <div class="btn">                    <span class="close">关闭</span>                    <span class="qr">确认修改</span>                </div>            </div>        </div>    </div>    </body></html>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207
  • 208
  • 209
  • 210
  • 211
  • 212
  • 213
  • 214
  • 215
  • 216
  • 217
  • 218
  • 219
  • 220
  • 221
  • 222
  • 223
  • 224
  • 225
  • 226
  • 227
  • 228
  • 229
  • 230
  • 231
  • 232
  • 233
  • 234
  • 235
  • 236
  • 237

本地存储

/********本地存储***************/            var ary;//声明用来接收本地存储的数组            var nextId = localStorage.nextId || 0;//nextId放与本地存储中            // 获取本地存储            function getInfo() {                return localStorage.list == undefined ? [] : JSON.parse(localStorage.list);            }            // 更新本地存储            function updateInfo() {                localStorage.list = JSON.stringify(ary);                ary = getInfo();                ary.forEach(function (item) {                    if (item.nextId == nextId) {                        nextId++;                        localStorage.nextId = nextId;                    } else {                        localStorage.nextId = nextId;                    }                })            }            // 添加数据到本地存储            function addInfo() {                //获取本地存储的内容                ary = getInfo();                // 定义对象,存入数据                var obj = {                    nextId: nextId++,                    username: $(".addList .username").children("input").val(),                    password: $(".addList .pwd").children("input").val()                }                //存入数组                ary.push(obj);                //清空                $(".addList input").val("");                //隐藏                $(".bg1").stop(true).fadeOut();                alert("添加成功");            }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46

完整代码

<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <meta http-equiv="X-UA-Compatible" content="IE=edge">    <meta name="viewport" content="width=device-width, initial-scale=1.0">    <title>Document</title>    <link rel="stylesheet" href="./font-awesome-4.7.0/css/font-awesome.min.css">    <style>        * {            margin: 0;            padding: 0;        }        .wrapper {            box-sizing: border-box;            position: relative;            width: 1349px;            margin: 0 auto;            padding-left: 175px;        }        .wrapper .add {            width: 110px;            line-height: 35px;            border-radius: 8px;            background-color: #327AB7;            color: #fff;            /* font-size: 18px;            font-weight: bold; */            text-align: center;        }        .top {            margin-top: 10px;        }        .top input {            line-height: 35px;        }        .top button {            line-height: 35px;            width: 80px;            background-color: #327AB7;            color: #fff;            border: none;            outline: none;            border-radius: 5px;        }        table tr {            width: 1000px;            text-align: left;            border-bottom: 1px solid lightgray;            /* background-color: #F9F9F9; */        }        th,        td {            width: 250px;            line-height: 50px;            float: left;            border-bottom: 1px solid lightgray;        }        tr span {            display: inline-block;            width: 60px;            line-height: 25px;            text-align: center;            color: #fff;            border-radius: 3px;            font-size: 14px;            margin-right: 10px;        }        tr .update {            background-color: #5CB75C;        }        tr .del {            background-color: #D9534F;        }        .bg1,        .bg2 {            position: absolute;            left: 0;            top: 0;            width: 100%;            height: 100vh;            background-color: rgba(0, 0, 0, 0.5);            display: none;        }        .addList,        .updateList {            position: relative;            z-index: 100;            /* top: 200px;            left: 200px;  */            width: 400px;            height: 230px;            border: 1px solid gray;            border-radius: 5px;            /* display: none; */            background-color: #fff;            margin-left: 450px;            margin-top: 200px;            z-index: 100;        }        .addList input,        .updateList input {            /* outline: none; */            width: 380px;            line-height: 25px;            margin-top: 20px;            margin-left: 8px;            outline: skyblue;            /* border-radius: 3px; */            /* margin: 0 auto; */        }        .addList .title,        .updateList .title {            margin-top: 10px;            padding-left: 10px;            padding-bottom: 20px;            border-bottom: 1px solid lightgray;        }        .addList .btn,        .updateList .btn {            text-align: right;            margin-top: 10px;            padding-top: 10px;            padding-right: 10px;            border-top: 1px solid lightgray;            font-size: 14px;        }        .addList .btn .close,        .updateList .btn .close {            display: inline-block;            width: 50px;            line-height: 30px;            text-align: center;            border-radius: 2px;            border: 1px solid gray;        }        .addList .btn .qr,        .updateList .btn .qr {            display: inline-block;            width: 80px;            line-height: 30px;            text-align: center;            border-radius: 2px;            border: 1px solid gray;            background-color: #327AB7;            color: #fff;        }    </style></head><body>    <div class="wrapper">        <div class="add">            <i class="fa fa-plus"></i><span>添加记录</span>        </div>        <div class="top">            <input type="text" placeholder="请输入用户名">            <button><i class="fa fa-search" aria-hidden="true"></i><span>查询</span></button>        </div>        <table border="0">            <tr class="first">                <th>id</th>                <th>username</th>                <th>password</th>                <th>操作</th>            </tr>        </table>        <div class="bg1">            <div class="addList">                <div class="title">                    添加记录                </div>                <div class="username">                    <input type="text" placeholder="请输入用户名">                </div>                <div class="pwd">                    <input type="password" placeholder="请输入密码">                </div>                <div class="btn">                    <span class="close">关闭</span>                    <span class="qr">确认添加</span>                </div>            </div>        </div>        <div class="bg2">            <div class="updateList">                <div class="title">                    修改记录                </div>                <input type="hidden" class="hidden">                <div class="username">                    <input type="text" placeholder="请输入用户名">                </div>                <div class="pwd">                    <input type="password" placeholder="请输入密码">                </div>                <div class="btn">                    <span class="close">关闭</span>                    <span class="qr">确认修改</span>                </div>            </div>        </div>    </div>    <script src="./js/jquery-3.6.0.min.js"></script>    <script>        $(function () {            //模态窗高度自动充满整个屏幕            $(window).scroll(function () {                var height = $(window).outerHeight();                var scroll = $(document).scrollTop();                $(".bg1").css("height", `${height + scroll}px`)                $(".bg2").css("height", `${height + scroll}px`)            })            //添加点击事件            $(".add").click(function () {                $(".bg1").stop(true).fadeIn();            })            //关闭点击事件            $(".bg1 .addList .close").click(function () {                $(".bg1").stop(true).fadeOut();            })            //关闭点击事件            $(".updateList .close").click(function () {                $(".bg2").stop(true).fadeOut();            })            /***********点击事件***************/            // 添加本地存储            $(".addList .qr").click(function () {                addInfo();                //更新本地存储                updateInfo();                // 渲染                show();                //tr背景色                bgColor();            })            // 查询            $(".top button").click(function () {                findInfo();                bgColor();            })            //删除            $("table").on('click', '.del', function () {                // 得到点击对象的nextId                var id = this.parentNode.parentNode.firstElementChild.innerText;                delInfo(id);                show();                bgColor();            })            // 修改            $("table").on('click', '.update', function () {                //得到修改数据的nextId                var getId = this.parentNode.parentNode.firstElementChild.innerText;                $(".hidden").val(getId);                update(getId)            })            $(".updateList .qr").click(function () {                qr();                show();                bgColor();            })            /********本地存储***************/            var ary;//声明用来接收本地存储的数组            var nextId = localStorage.nextId || 0;//nextId放与本地存储中            // 获取本地存储            function getInfo() {                return localStorage.list == undefined ? [] : JSON.parse(localStorage.list);            }            // 更新本地存储            function updateInfo() {                localStorage.list = JSON.stringify(ary);                ary = getInfo();                ary.forEach(function (item) {                    if (item.nextId == nextId) {                        nextId++;                        localStorage.nextId = nextId;                    } else {                        localStorage.nextId = nextId;                    }                })            }            // 添加数据到本地存储            function addInfo() {                //获取本地存储的内容                ary = getInfo();                // 定义对象,存入数据                var obj = {                    nextId: nextId++,                    username: $(".addList .username").children("input").val(),                    password: $(".addList .pwd").children("input").val()                }                //存入数组                ary.push(obj);                //清空                $(".addList input").val("");                //隐藏                $(".bg1").stop(true).fadeOut();                alert("添加成功");            }            /*********************渲染**************************/            // 4、渲染            show();//加载时渲染            function show() {                ary = getInfo();                //清空除了表头的tr内容                $("tr:not(.first)").hide();                //遍历添加tr                for (var item of ary) {                    var tr = $(`<tr>                <td class="id">${item.nextId}</td>                <td>${item.username}</td>                <td>${item.password}</td>                <td><span class="update"><i class="fa fa-pencil" aria-hidden="true"></i>修改</span><span class="del"><i                            class="fa fa-trash" aria-hidden="true"></i>删除</span></td>            </tr>`)                    $("table").append(tr);                }            }            /*********************************************/            /******************查询************************/            function findInfo() {                //得到输入框的内容                var val = $(".top input").val();                //过滤出符合的数组对象                var ary1 = ary.filter(function (item) {                    // return JSON.stringify(item).includes(val) == true;                    return item.username.includes(val) == true;                })                //清空                $("tr:not(.first)").hide();                //渲染查询出来的数据                for (var tag of ary1) {                    var tr = $(`<tr>                <td class="id">${tag.nextId}</td>                <td>${tag.username}</td>                <td>${tag.password}</td>                <td><span class="update"><i class="fa fa-pencil" aria-hidden="true"></i>修改</span><span class="del"><i                            class="fa fa-trash" aria-hidden="true"></i>删除</span></td>           </tr> `)                    $("table").append(tr);                }            }            /****************删除*************************/            function delInfo(id) {                // 获取其在数组中的下标                var index = ary.findIndex(item => item.nextId == id);                if (confirm("确认删除吗?")) {                    //从数组中删除                    ary.splice(index, 1);                    updateInfo();                }            }            /**************修改************************/            function update(getId) {                //将数据事先加载到修改框中                for (var item of ary) {                    if (item.nextId == getId) {                        $(".updateList .username").children("input").val(item.username)                        $(".updateList .pwd").children("input").val(item.password)                    }                }                $(".bg2").stop(true).fadeIn();            }            /***********确认按钮*********************/            function qr() {                //拿到修改数据的nextId                var num = $(".hidden").val();                ary = getInfo();                // 遍历数组找到目标数据,并进行修改                for (var item of ary) {                    if (item.nextId == num) {                        item.username = $(".updateList .username").children("input").val();                        item.password = $(".updateList .pwd").children("input").val();                        $(".updateList .username").children("input").val("")                        $(".updateList .pwd").children("input").val("");                    }                };                updateInfo();                $(".bg2").stop(true).fadeOut();            }            /******************背景色**********************/            //tr背景色            bgColor();            function bgColor() {                $("tr:even").css("background-color", "#FEFEFE");                $("tr:odd").css("background-color", "#F9F9F9");            }        })    </script></body></html>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207
  • 208
  • 209
  • 210
  • 211
  • 212
  • 213
  • 214
  • 215
  • 216
  • 217
  • 218
  • 219
  • 220
  • 221
  • 222
  • 223
  • 224
  • 225
  • 226
  • 227
  • 228
  • 229
  • 230
  • 231
  • 232
  • 233
  • 234
  • 235
  • 236
  • 237
  • 238
  • 239
  • 240
  • 241
  • 242
  • 243
  • 244
  • 245
  • 246
  • 247
  • 248
  • 249
  • 250
  • 251
  • 252
  • 253
  • 254
  • 255
  • 256
  • 257
  • 258
  • 259
  • 260
  • 261
  • 262
  • 263
  • 264
  • 265
  • 266
  • 267
  • 268
  • 269
  • 270
  • 271
  • 272
  • 273
  • 274
  • 275
  • 276
  • 277
  • 278
  • 279
  • 280
  • 281
  • 282
  • 283
  • 284
  • 285
  • 286
  • 287
  • 288
  • 289
  • 290
  • 291
  • 292
  • 293
  • 294
  • 295
  • 296
  • 297
  • 298
  • 299
  • 300
  • 301
  • 302
  • 303
  • 304
  • 305
  • 306
  • 307
  • 308
  • 309
  • 310
  • 311
  • 312
  • 313
  • 314
  • 315
  • 316
  • 317
  • 318
  • 319
  • 320
  • 321
  • 322
  • 323
  • 324
  • 325
  • 326
  • 327
  • 328
  • 329
  • 330
  • 331
  • 332
  • 333
  • 334
  • 335
  • 336
  • 337
  • 338
  • 339
  • 340
  • 341
  • 342
  • 343
  • 344
  • 345
  • 346
  • 347
  • 348
  • 349
  • 350
  • 351
  • 352
  • 353
  • 354
  • 355
  • 356
  • 357
  • 358
  • 359
  • 360
  • 361
  • 362
  • 363
  • 364
  • 365
  • 366
  • 367
  • 368
  • 369
  • 370
  • 371
  • 372
  • 373
  • 374
  • 375
  • 376
  • 377
  • 378
  • 379
  • 380
  • 381
  • 382
  • 383
  • 384
  • 385
  • 386
  • 387
  • 388
  • 389
  • 390
  • 391
  • 392
  • 393
  • 394
  • 395
  • 396
  • 397
  • 398
  • 399
  • 400
  • 401
  • 402
  • 403
  • 404
  • 405
  • 406
  • 407
  • 408
  • 409
  • 410
  • 411
  • 412
  • 413
  • 414
  • 415
  • 416
  • 417
  • 418
  • 419
  • 420
  • 421
  • 422
  • 423
  • 424
  • 425
  • 426
  • 427
  • 428
  • 429
  • 430
  • 431
  • 432
  • 433
  • 434
  • 435
  • 436
  • 437
  • 438
  • 439
  • 440
  • 441
  • 442
  • 443
  • 444
  • 445
  • 446
  • 447
  • 448
  • 449
  • 450
  • 451
  • 452
  • 453
  • 454
  • 455
  • 456
  • 457
  • 458
  • 459
  • 460
  • 461
  • 462
  • 463
  • 464

效果图:




网站建设定制开发 软件系统开发定制 定制软件开发 软件开发定制 定制app开发 app开发定制 app开发定制公司 电商商城定制开发 定制小程序开发 定制开发小程序 客户管理系统开发定制 定制网站 定制开发 crm开发定制 开发公司 小程序开发定制 定制软件 收款定制开发 企业网站定制开发 定制化开发 android系统定制开发 定制小程序开发费用 定制设计 专注app软件定制开发 软件开发定制定制 知名网站建设定制 软件定制开发供应商 应用系统定制开发 软件系统定制开发 企业管理系统定制开发 系统定制开发