首页 技术 正文
技术 2022年11月6日
0 收藏 364 点赞 1,100 浏览 6212 个字

https://github.com/wenzhixin/bootstrap-table-examples/blob/master/crud/index.html

<!DOCTYPE html>
<html>
<head>
    <title>CRUD Table</title>
    <meta charset=”utf-8″>
    <link rel=”stylesheet” href=”../assets/bootstrap/css/bootstrap.min.css”>
    <link rel=”stylesheet” href=”../assets/bootstrap-table/src/bootstrap-table.css”>
    <link rel=”stylesheet” href=”../assets/examples.css”>
    <style>
        .update {
            color: #333;
            margin-right: 5px;
        }
        .remove {
            color: red;
            margin-left: 5px;
        }
        .alert {
            padding: 0 14px;
            margin-bottom: 0;
            display: inline-block;
        }
    </style>
    <script src=”../assets/jquery.min.js”></script>
    <script src=”../assets/bootstrap/js/bootstrap.min.js”></script>
    <script src=”../assets/bootstrap-table/src/bootstrap-table.js”></script>
    <script src=”../ga.js”></script>
</head>
<body>
    <div class=”container”>
        <h1>CRUD Table</h1>
        <p class=”toolbar”>
            <a class=”create btn btn-default” href=”javascript:”>Create Item</a>
            <span class=”alert”></span>
        </p>
        <table id=”table”
               data-show-refresh=”true”
               data-show-columns=”true”
               data-search=”true”
               data-query-params=”queryParams”
               data-toolbar=”.toolbar”>
            <thead>
            <tr>
                <th data-field=”name”>Name</th>
                <th data-field=”stargazers_count”>Stars</th>
                <th data-field=”forks_count”>Forks</th>
                <th data-field=”description”>Description</th>
                <th data-field=”action”
                    data-align=”center”
                    data-formatter=”actionFormatter”
                    data-events=”actionEvents”>Action</th>
            </tr>
            </thead>
        </table>
    </div>

<div id=”modal” class=”modal fade”>
        <div class=”modal-dialog”>
            <div class=”modal-content”>
                <div class=”modal-header”>
                    <button type=”button” class=”close” data-dismiss=”modal” aria-label=”Close”><span aria-hidden=”true”>&times;</span></button>
                    <h4 class=”modal-title”></h4>
                </div>
                <div class=”modal-body”>
                    <div class=”form-group”>
                        <label>Name</label>
                        <input type=”text” class=”form-control” name=”name” placeholder=”Name”>
                    </div>
                    <div class=”form-group”>
                        <label>Stars</label>
                        <input type=”number” class=”form-control” name=”stargazers_count” placeholder=”Stars”>
                    </div>
                    <div class=”form-group”>
                        <label>Forks</label>
                        <input type=”number” class=”form-control” name=”forks_count” placeholder=”Forks”>
                    </div>
                    <div class=”form-group”>
                        <label>Description</label>
                        <input type=”text” class=”form-control” name=”description” placeholder=”Description”>
                    </div>
                </div>
                <div class=”modal-footer”>
                    <button type=”button” class=”btn btn-default” data-dismiss=”modal”>Close</button>
                    <button type=”button” class=”btn btn-primary submit”>Submit</button>
                </div>
            </div><!– /.modal-content –>
        </div><!– /.modal-dialog –>
    </div><!– /.modal –>
<script>
    var API_URL = ‘http://’ + location.host + ‘:3001/list/’;
    var $table = $(‘#table’).bootstrapTable({url: API_URL}),
        $modal = $(‘#modal’).modal({show: false}),
        $alert = $(‘.alert’).hide();
    $(function () {
        // create event
        $(‘.create’).click(function () {
            showModal($(this).text());
        });
        $modal.find(‘.submit’).click(function () {
            var row = {};
            $modal.find(‘input[name]’).each(function () {
                row[$(this).attr(‘name’)] = $(this).val();
            });
            $.ajax({
                url: API_URL + ($modal.data(‘id’) || ”),
                type: $modal.data(‘id’) ? ‘put’ : ‘post’,
                contentType: ‘application/json’,
                data: JSON.stringify(row),
                success: function () {
                    $modal.modal(‘hide’);
                    $table.bootstrapTable(‘refresh’);
                    showAlert(($modal.data(‘id’) ? ‘Update’ : ‘Create’) + ‘ item successful!’, ‘success’);
                },
                error: function () {
                    $modal.modal(‘hide’);
                    showAlert(($modal.data(‘id’) ? ‘Update’ : ‘Create’) + ‘ item error!’, ‘danger’);
                }
            });
        });
    });
    function queryParams(params) {
        return {};
    }
    function actionFormatter(value) {
        return [
            ‘<a class=”update” href=”javascript:” title=”Update Item”><i class=”glyphicon glyphicon-edit”></i></a>’,
            ‘<a class=”remove” href=”javascript:” title=”Delete Item”><i class=”glyphicon glyphicon-remove-circle”></i></a>’,
        ].join(”);
    }
    // update and delete events
    window.actionEvents = {
        ‘click .update’: function (e, value, row) {
            showModal($(this).attr(‘title’), row);
        },
        ‘click .remove’: function (e, value, row) {
            if (confirm(‘Are you sure to delete this item?’)) {
                $.ajax({
                    url: API_URL + row.id,
                    type: ‘delete’,
                    success: function () {
                        $table.bootstrapTable(‘refresh’);
                        showAlert(‘Delete item successful!’, ‘success’);
                    },
                    error: function () {
                        showAlert(‘Delete item error!’, ‘danger’);
                    }
                })
            }
        }
    };
    function showModal(title, row) {
        row = row || {
            id: ”,
            name: ”,
            stargazers_count: 0,
            forks_count: 0,
            description: ”
        }; // default row value
        $modal.data(‘id’, row.id);
        $modal.find(‘.modal-title’).text(title);
        for (var name in row) {
            $modal.find(‘input[name=”‘ + name + ‘”]’).val(row[name]);
        }
        $modal.modal(‘show’);
    }
    function showAlert(title, type) {
        $alert.attr(‘class’, ‘alert alert-‘ + type || ‘success’)
              .html(‘<i class=”glyphicon glyphicon-check”></i> ‘ + title).show();
        setTimeout(function () {
            $alert.hide();
        }, 3000);
    }
</script>
</body>
</html>

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,026
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,517
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,364
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,145
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,779
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,856