您的位置:首页 > Web前端 > JQuery

jquery插件dataTable. 添加一行记录---触发click()事件

2016-09-02 15:39 375 查看
n<a target=_blank href="https://cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css">https://cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css</a>
<span style="font-size:24px;">js:</span>
$(document).ready(function() {
var t = $('#example').DataTable();
var counter = 1;

$('#addRow').on( 'click', function () {
t.row.add( [
counter +'.1',
counter +'.2',
counter +'.3',
counter +'.4',
counter +'.5'
] ).draw( false );

counter++;
} );

// Automatically add a first row of data
$('#addRow').click();

} );


<span style="font-size:24px;">html:</span>引入:<a target=_blank href="https://cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css">https://cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css</a>

<table id="example" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
<th>Column 4</th>
<th>Column 5</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
<th>Column 4</th>
<th>Column 5</th>
</tr>
</tfoot>
</table>


指定列:

var table = $('#example').DataTable();

 

table.row.add( {

        "name":       "Tiger Nixon",

        "position":   "System Architect",

        "salary":     "$3,120",

        "start_date": "2011/04/25",

        "office":     "Edinburgh",

        "extn":       "5421"

    } ).draw();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: