bootstrap table小案例
Bootstrap Table是基于Bootstrap的輕量級表格插件,只需要簡單的配置就可以實現(xiàn)強大的支持固定表頭、單復(fù)選、排序、分頁、搜索以及自定義表頭等功能。
1、所需要的庫:
bootstrap.min.css
bootstrap-table.css
jquery.min.js
bootstrap.min.js
bootstrap-table.js
2、Bootstrap Table獲取數(shù)據(jù)的方式:
Bootstrap Table通過data屬性標(biāo)簽或者JavaScript來顯示表格數(shù)據(jù):
(1)、通過data屬性標(biāo)簽
在表格中設(shè)置data-toggle=“table”,此方式可以在不寫JavaScript的情況下啟用Bootstrap Table。
<table data-toggle="table" data-url="data.json"> <thead> ... </thead> </table>
(2)、通過JavaScipt向表格傳入數(shù)據(jù):
<table id="table"></table> <1>、簡單的靜態(tài)數(shù)據(jù) $('#table').bootstrapTable({ columns: [{ field: 'id', title: 'Item ID' }, { field: 'username', title: 'Item Username' }, { field: 'password', title: 'Item Passowrd' }], data: [{ id: 1, username: 'Item 1', passowrd: '$1' }, { id: 2, username: 'Item 2', password: '$2' }]}); <2>、通過url獲取數(shù)據(jù) $('#table').bootstrapTable({ url: 'data1.json', columns: [{ field: 'id', title: 'Item ID' }, { field: 'username', title: 'Item Username' }, { field: 'passowrd', title: 'Item Passowrd' }, ]});
3、Bootstrap Table簡單的demo:
<!doctype html> <html> <head> <meta charset="utf-8"> <title>Bootstrap Table的demo</title> <link rel="stylesheet" href="bootstrap.css"> <link rel="stylesheet" href="bootstrap-table.css"> </head> <body> <table id="table"></table> <!--引入相關(guān)的js文件--> <script src="jquery.min.js"></script> <script src="bootstrap.js"></script> <script src="bootstrap-table.js"></script> <!--自定義javaScript--> <script> $('#table').bootstrapTable({ columns: [{ field: 'id', title: 'Item ID' }, { field: 'username', title: 'Item Username' }, { field: 'passsword', title: 'Item Password' }], data: [{ id: 1, username: 'Item 1', passowrd: '123' }, { id: 2, username: 'Item 2', passowrd: '123 }] }); </script> </body> </html>
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
如果大家還想深入學(xué)習(xí),可以點擊這里進行學(xué)習(xí),再為大家附兩個精彩的專題:Bootstrap學(xué)習(xí)教程 Bootstrap實戰(zhàn)教程
相關(guān)文章
微信小程序 bindtap 事件多參數(shù)傳遞的代碼示例
在微信小程序中,我們無法直接通過 bindtap="handleClick(1,2,3)" 的方式傳遞參數(shù),而是通過自定義屬性data- 的方式傳遞,并在事件回調(diào)函數(shù)中通過event.currentTarget.dataset獲取這些參數(shù),本文給大家介紹小程序 bindtap 事件多參數(shù)傳遞的實例代碼,感興趣的朋友一起看看吧2023-12-12bootstrap提示標(biāo)簽、提示框?qū)崿F(xiàn)代碼
這篇文章主要為大家詳細介紹了bootstrap提示標(biāo)簽、提示框的實現(xiàn)代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-12-12