var t = $('#passwdHOST').DataTable({ 'searching': true, 'ordering': false, 'autoWidth': false, dom: 'Bfrtip', buttons: [{ text: "导出到Execl", extend: 'excelHtml5', //className:'execl' //customize: function( xlsx ) { // var sheet = xlsx.xl.worksheets['sheet1.xml']; //$('row c[r^="C"]', sheet).attr( 's', '2' ); //} },{ text: '新建主机', action: function ( e, dt, node, config ) { //e: // 触发事件的事件对象 //dt: // 主机DataTable的DataTables API实例 //node //单击的按钮节点的jQuery实例 //config //按钮的配置对象 create_row(e, dt, node, config); } },{ text: '删除主机', action: function ( e, dt, node, config ) { //e: // 触发事件的事件对象 //dt: // 主机DataTable的DataTables API实例 //node //单击的按钮节点的jQuery实例 //config //按钮的配置对象 create_row(e, dt, node, config); } } ], language: { "decimal": "", "emptyTable": "数据正在加载中,请稍后...", "info": "显示 _START_ 到 _END_ 页共 _TOTAL_ 条", "infoEmpty": "显示 0 到 0 页共 0 条", "infoFiltered": "(filtered from _MAX_ total entries)", "infoPostFix": "", "thousands": ",", "lengthMenu": "显示 _MENU_ 条", "loadingRecords": "加载中...", "processing": "处理中...", "search": "搜索:", "zeroRecords": "没有匹配项", "paginate": { "first": "First", "last": "Last", "next": "下页", "previous": "上页" }, "aria": { "sortAscending": ": activate to sort column ascending", "sortDescending": ": activate to sort column descending" }, }, }); $.ajax({ url: '/passwd/api/hosts', type: "POST", data: ajax_data, success: function (data) { var rowNode = t.row.add( [ data.id, data.ip, data.hostname, data.os, data.protocal, data.port, data.comments, "<div class='btn-group'>" + "<button type='button' class='" + select + " btn " + btninfo + " ' data-target='#modal .bd-example-modal-lg ' >查看</button>" + "<button type='button' class='btn btn-info dropdown-toggle' data-toggle='dropdown'>" + " <span class='caret'></span>" + "</button>" + "<ul class='dropdown-menu' role='menu'>" + " <li><a href='passwdLOG.html'>查看密码修改日志</a></li>" + "</ul>" + "<button type='button' class='" + append + " btn " + btnsuccess + "' data-target='#modal .bd-example-modal-lg'>增加</button>" + "<button type='button' class='" + modify + " btn " + btnwarning + "' data-target='#modal .bd-example-modal-lg' >修改</button>" + "<button type='button' class='" + del + " btn " + btndanger + "' data-target='#modal .bd-example-modal-lg' >删除</button>" + "</div>" ] ).draw().node(); $(t.table().body()).prepend($(rowNode)) // 将新添加的一行插入到第一行 $( rowNode ).css( 'color', 'red' ) //修改新加一行的样式