第一次使用Bootstrap-table這個表格插件,記錄一下使用過程中遇到的問題。
|引入CSS文件
<link rel="stylesheet" href="bootstrap.min.css"><link rel="stylesheet" href="bootstrap-table.css">
|引入相關庫
我們需要引入Jquery庫、bootstrap庫、以及bootstrap-table.js文件
<script src="jquery.min.js"></script><script src="bootstrap.min.js"></script><script src="bootstrap-table.js"></script><-- put your locale files after bootstrap-table.js --><script src="bootstrap-table-zh-CN.js"></script>
|啟用Bootstrap Table插件:
官方文檔中給出了我們有兩種那個方式來啟用bootstrap-table插件:
1、通過data屬性的方式:
<table data-toggle="table"> <thead> <tr> <th>Item ID</th> <th>Item Name</th> <th>Item Price</th> </tr> </thead> <tbody> <tr> <td>1</td> <td>Item 1</td> <td>$1</td> </tr> <tr> <td>2</td> <td>Item 2</td> <td>$2</td> </tr> </tbody></table>
2、通過js的方式:
//只需要HTML中寫下table標簽,并設置id<table id="table"></table>
$('#table').bootstrapTable({ columns: [{ field: 'id', title: 'Item ID' }, { field: 'name', title: 'Item Name' }, { field: 'price', title: 'Item Price' }], data: [{ id: 1, name: 'Item 1', price: '$1' }, { id: 2, name: 'Item 2', price: '$2' }]});也可以通過url獲取數據
$('#table').bootstrapTable({ url: 'data1.json', columns: [{ field: 'id', //與返回值的JSON數據的key值對應 title: 'Item ID' //列名 }, { field: 'name', title: 'Item Name' }, { field: 'price', title: 'Item Price' }, ]});以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VeVb武林網。
新聞熱點
疑難解答