文档阅读

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!--<link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="css/bootstrap-table.min.css">
    <script src="js/jquery.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <!--<script src="assets/bootstrap2.3/js/bootstrap.min.js"></script>-->
    <!--<script src="js/tableExport.js"></script>
    <script src="js/jquery.base64.js"></script>
    <script src="js/bootstrap-table.js"></script>-->
    <!--<script src="js/bootstrap-table-export.js"></script>-->
    <link rel="stylesheet" type="text/css" href="css1/bootstrap-table.css" />
    <link rel="stylesheet" type="text/css" href="css1/bootstrap.min.css" />
    <script src="js1/jquery.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="js1/bootstrap-table.js" type="text/javascript" charset="utf-8"></script>
    <script src="js1/bootstrap.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="js1/bootstrap-table-zh-CN.js" type="text/javascript" charset="utf-8"></script>
    <!--<script src="js/bootstrap-table-zh-CN.js" type="text/javascript" charset="utf-8"></script>-->
    <style type="text/css">
        .wd{
            width: 16px;
        }
    </style>
    <script type="text/javascript">
        var a = [{
                "id": 0,
                "name": "阿萨德",
                "price": "<a href='#'>![](./删除.png)</a>"
            },
            {
                "id": 1,
                "name": "Item 1",
                "price": "$1"
            },
            {
                "id": 2,
                "name": "Item 2",
                "price": "$2"
            },
            {
                "id": 3,
                "name": "Item 3",
                "price": "$3"
            },
            {
                "id": 4,
                "name": "Item 4",
                "price": "$4"
            },
            {
                "id": 5,
                "name": "Item 5",
                "price": "$5"
            },
            {
                "id": 6,
                "name": "Item 6",
                "price": "$6"
            },
            {
                "id": 7,
                "name": "Item 7",
                "price": "$7"
            },
            {
                "id": 8,
                "name": "Item 8",
                "price": "$8"
            },
            {
                "id": 9,
                "name": "Item 9",
                "price": "$9"
            },
            {
                "id": 10,
                "name": "Item 10",
                "price": "$10"
            },
            {
                "id": 11,
                "name": "Item 11",
                "price": "$11"
            },
            {
                "id": 12,
                "name": "Item 12",
                "price": "$12"
            },
            {
                "id": 13,
                "name": "Item 13",
                "price": "$13"
            },
            {
                "id": 14,
                "name": "Item 14",
                "price": "$14"
            },
            {
                "id": 15,
                "name": "Item 15",
                "price": "$15"
            },
            {
                "id": 16,
                "name": "Item 16",
                "price": "$16"
            },
            {
                "id": 17,
                "name": "Item 17",
                "price": "$17"
            },
            {
                "id": 18,
                "name": "Item 18",
                "price": "$18"
            },
            {
                "id": 19,
                "name": "Item 19",
                "price": "$19"
            },
            {
                "id": 20,
                "name": "Item 20",
                "price": "$20"
            },
            {
                "id": 0,
                "name": "阿萨德",
                "price": "<a href='#' id='btn'>修改</a>"
            },
            {
                "id": 1,
                "name": "Item 1",
                "price": "$1"
            },
            {
                "id": 2,
                "name": "Item 2",
                "price": "$2"
            },
            {
                "id": 3,
                "name": "Item 3",
                "price": "$3"
            },
            {
                "id": 4,
                "name": "Item 4",
                "price": "$4"
            },
            {
                "id": 5,
                "name": "Item 5",
                "price": "$5"
            },
            {
                "id": 6,
                "name": "Item 6",
                "price": "$6"
            },
            {
                "id": 7,
                "name": "Item 7",
                "price": "$7"
            },
            {
                "id": 8,
                "name": "Item 8",
                "price": "$8"
            },
            {
                "id": 9,
                "name": "Item 9",
                "price": "$9"
            },
            {
                "id": 10,
                "name": "Item 10",
                "price": "$10"
            },
            {
                "id": 11,
                "name": "Item 11",
                "price": "$11"
            },
            {
                "id": 12,
                "name": "Item 12",
                "price": "$12"
            },
            {
                "id": 13,
                "name": "Item 13",
                "price": "$13"
            },
            {
                "id": 14,
                "name": "Item 14",
                "price": "$14"
            },
            {
                "id": 15,
                "name": "Item 15",
                "price": "$15"
            },
            {
                "id": 16,
                "name": "Item 16",
                "price": "$16"
            },
            {
                "id": 17,
                "name": "Item 17",
                "price": "$17"
            },
            {
                "id": 18,
                "name": "Item 18",
                "price": "$18"
            },
            {
                "id": 19,
                "name": "Item 19",
                "price": "$19"
            },
            {
                "id": 20,
                "name": "Item 20",
                "price": "$20"
            },
            {
                "id": 0,
                "name": "阿萨德",
                "price": "<a href='#' id='btn'>修改</a>"
            },
            {
                "id": 1,
                "name": "Item 1",
                "price": "$1"
            },
            {
                "id": 2,
                "name": "Item 2",
                "price": "$2"
            },
            {
                "id": 3,
                "name": "Item 3",
                "price": "$3"
            },
            {
                "id": 4,
                "name": "Item 4",
                "price": "$4"
            },
            {
                "id": 5,
                "name": "Item 5",
                "price": "$5"
            },
            {
                "id": 6,
                "name": "Item 6",
                "price": "$6"
            },
            {
                "id": 7,
                "name": "Item 7",
                "price": "$7"
            },
            {
                "id": 8,
                "name": "Item 8",
                "price": "$8"
            },
            {
                "id": 9,
                "name": "Item 9",
                "price": "$9"
            },
            {
                "id": 10,
                "name": "Item 10",
                "price": "$10"
            },
            {
                "id": 11,
                "name": "Item 11",
                "price": "$11"
            },
            {
                "id": 12,
                "name": "Item 12",
                "price": "$12"
            },
            {
                "id": 13,
                "name": "Item 13",
                "price": "$13"
            },
            {
                "id": 14,
                "name": "Item 14",
                "price": "$14"
            },
            {
                "id": 15,
                "name": "Item 15",
                "price": "$15"
            },
            {
                "id": 16,
                "name": "Item 16",
                "price": "$16"
            },
            {
                "id": 17,
                "name": "Item 17",
                "price": "$17"
            },
            {
                "id": 18,
                "name": "Item 18",
                "price": "$18"
            },
            {
                "id": 19,
                "name": "Item 19",
                "price": "$19"
            },
            {
                "id": 20,
                "name": "Item 20",
                "price": "$20"
            },
            {
                "id": 0,
                "name": "阿萨德",
                "price": "<a href='#' id='btn'>修改</a>"
            },
            {
                "id": 1,
                "name": "Item 1",
                "price": "$1"
            },
            {
                "id": 2,
                "name": "Item 2",
                "price": "$2"
            },
            {
                "id": 3,
                "name": "Item 3",
                "price": "$3"
            },
            {
                "id": 4,
                "name": "Item 4",
                "price": "$4"
            },
            {
                "id": 5,
                "name": "Item 5",
                "price": "$5"
            },
            {
                "id": 6,
                "name": "Item 6",
                "price": "$6"
            },
            {
                "id": 7,
                "name": "Item 7",
                "price": "$7"
            },
            {
                "id": 8,
                "name": "Item 8",
                "price": "$8"
            },
            {
                "id": 9,
                "name": "Item 9",
                "price": "$9"
            },
            {
                "id": 10,
                "name": "Item 10",
                "price": "$10"
            },
            {
                "id": 11,
                "name": "Item 11",
                "price": "$11"
            },
            {
                "id": 12,
                "name": "Item 12",
                "price": "$12"
            },
            {
                "id": 13,
                "name": "Item 13",
                "price": "$13"
            },
            {
                "id": 14,
                "name": "Item 14",
                "price": "$14"
            },
            {
                "id": 15,
                "name": "Item 15",
                "price": "$15"
            },
            {
                "id": 16,
                "name": "Item 16",
                "price": "$16"
            },
            {
                "id": 17,
                "name": "Item 17",
                "price": "$17"
            },
            {
                "id": 18,
                "name": "Item 18",
                "price": "$18"
            },
            {
                "id": 19,
                "name": "Item 19",
                "price": "$19"
            },
            {
                "id": 20,
                "name": "Item 20",
                "price": "$20"
            }
        ]
    </script>
</head>
<style type="text/css">
    .aa{
        background-color: red;
    }
</style>
<body>
    <div class="container">
        <!--<div>
            <label>Cells: </label><input id="cells" type="text" placeholder="Cells" value="5">
            <label>Rows: </label><input id="rows" type="text" placeholder="Rows" value="100">
            <button id="build" class="btn btn-default">Build</button>
        </div>-->
        <!--
            data-toggle="table"  不用写 JavaScript 直接启用表格。
            data-classes='table-no-bordered    消除边框
        -->
        <table id="table" data-show-columns="true" data-search="true" data-show-refresh="true" data-show-toggle="true" data-pagination="true" data-show-pagination-switch="true" data-height="500" data-show-header="true" data-striped='true' data-pagination-pre-text="上一页" data-pagination-next-text='下一页'>
            <thead>
                <tr>
                    <th data-field="state" data-checkbox="true"></th>
                    <th data-field="id" data-formatter="idFormatter" data-stripe="true">ID</th>
                    <th data-field="name">Item Name</th>
                    <th data-field="price" id="item" data-icons={paginationSwitchDown: 'glyphicon-collapse-down icon-chevron-down'}>Item Price</th>
                </tr>
            </thead>
            <button id="btn">提交</button>
            <button id="btn1">提交1</button>
        </table>

    </div>
    <script>
        function idFormatter(value) {
            return value + 100;
        }

        $('#table').bootstrapTable({
            data: a
        });
        $(function() {
            $("#btn").click(function() {
                var ids = $.map($('#table').bootstrapTable('getSelections'), function(row) {
                    return row;
                });
                alert('您选择的id是: ' + JSON.stringify(ids));
            });
            //删除哪里行

// $("#btn1").click(function() {
// $('#table').bootstrapTable('removeByUniqueId', 1);
// });

        })
        
        // 全局判断

// $('#table').on('click-row.bs.table', function(e, row, element) {
// var bln = window.confirm("确定吗?");
// console.log(row.id)
// if(bln)
//// $('#table').bootstrapTable('removeByUniqueId', {index: row.id});
// $('#table').bootstrapTable('hideRow', {index: row.id});
//
// $('.aa').removeClass('aa'); //去除之前选中的行的,选中样式
// $(element).addClass('aa'); //添加当前选中的 success样式用于区别
// console.log($(element));
// });

    //针对列进行判断
        $('#table').on('click-cell.bs.table', function(field, value, row, $element) { 

// var bln = window.confirm("确定吗?");
// console.log(row.id)
// if(bln)
//// $('#table').bootstrapTable('removeByUniqueId', {index: row.id});
// $('#table').bootstrapTable('hideRow', {index: row.id});
//
// $('.aa').removeClass('aa'); //去除之前选中的行的,选中样式
// $(element).addClass('aa'); //添加当前选中的 success样式用于区别
console.log($element);
console.log(field);
console.log(value);
console.log(row);
// alert(1);
});

        function getSelectedRow() { 
            var index = $('#teacher_table').find('tr.success').data('index'); //获得选中的行
             
            return $('#teacher_table').bootstrapTable('getData')[index]; //返回选中行所有数据
        }

        /// 指定的行 显示或隐藏
        //  $(function () {
        //      $("#btn1").click(function () {
        //          $('#table').bootstrapTable('showRow', {index: 1});
        //      });
        //
        //     $("#btn1").click(function () {
        //          $('#table').bootstrapTable('hideRow', {index: 1});
        //      });
        //  });
        //          

        // updateRow 更新指定行的数据
        //          $(function() {
        //              $("#btn1").click(function() {
        //                  var randomId = 100 + ~~(Math.random() * 100);
        //                  $('#table').bootstrapTable('updateRow', {
        //                      index: 1,
        //                      row: {
        //                          id: randomId,
        //                          name: 'Item ' + randomId,
        //                          price: '$' + randomId
        //                      }
        //                  });
        //              });
        //          });

        // 插入指定行之前 index是 id索引
        //  $(function () {
        //      $("#btn1").click(function () {
        //          var randomId = 100 + ~~(Math.random() * 100);
        //          $('#table').bootstrapTable('insertRow', {
        //              index: 0,
        //              row: {
        //                  id: randomId,
        //                  name: 'Item ' + randomId,
        //                  price: '$' + randomId
        //              }
        //          });
        //      });
        //  });

        //插入数据到尾部  append  头部 prepend
        //          $(function() {
        //              $("#btn1").click(function() {
        //                  $('#table').bootstrapTable('prepend', randomData());
        //                  $('#table').bootstrapTable('scrollTo', 'top');
        //              });
        //          });
        //
        //          function randomData() {
        //              var startId = ~~(Math.random() * 100),
        //                  rows = [];
        //
        //              for(var i = 0; i < 1; i++) {
        //                  rows.push({
        //                      id: startId + i,
        //                      name: 'test' + (startId + i),
        //                      price: '$' + (startId + i)
        //                  });
        //              }
        //              return rows;
        //          }

        //随机数据
        //              $("#btn1").click(function() {
        //                  $("#table").bootstrapTable('load', randomData());
        //              });
        //          function randomData() {
        //              var startId = ~~(Math.random() * 100),
        //                  rows = [];
        //
        //              for(var i = 0; i < 10; i++) {
        //                  rows.push({
        //                      id: startId + i,
        //                      name: 'test' + (startId + i),
        //                      price: '$' + (startId + i)
        //                  });
        //              }
        //              return rows;
        //          }
    </script>
</body>

</html>

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 216,001评论 6 498
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,210评论 3 392
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 161,874评论 0 351
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,001评论 1 291
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,022评论 6 388
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,005评论 1 295
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,929评论 3 416
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,742评论 0 271
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,193评论 1 309
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,427评论 2 331
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,583评论 1 346
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,305评论 5 342
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,911评论 3 325
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,564评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,731评论 1 268
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,581评论 2 368
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,478评论 2 352

推荐阅读更多精彩内容