jQuery實現(xiàn)動態(tài)給table賦值的方法示例
本文實例講述了jQuery實現(xiàn)動態(tài)給table賦值的方法。分享給大家供大家參考,具體如下:
html
請忽視各種class,因為前端用的是layui
<table class="layui-table" lay-skin="line" id="datas">
<colgroup>
<col width="150">
<col width="200">
<col>
</colgroup>
<thead>
<tr>
<th>昵稱</th>
<th>加入時間</th>
<th>簽名</th>
</tr>
</thead>
<tbody>
<tr id="template">
<td id="id"></td>
<td id="url"></td>
<td id="title"></td>
</tr>
</tbody>
</table>
js代碼
<script>
var data = [{
"id": 1,
"url": "http://www.jqcool.net",
"switch": 1,
"order": 1,
"pid": 0,
"title": "Online Program knowledge share and study platform"
},
{
"id": 2,
"url": "http://www.baidu.com",
"switch": 0,
"order": 2,
"pid": 2,
"title": "這是測試的數(shù)數(shù)據(jù)這是測試的數(shù)數(shù)據(jù)"
},
{
"id": 3,
"url": "http://www.taobao.com",
"switch": 0,
"order": 3,
"pid": 2,
"title": "淘寶購物"
},
{
"id": 4,
"url": "http://www.jqcool.net1",
"switch": 1,
"order": 4,
"pid": 2,
"title": "Online Program knowledge share and study platform2"
},
{
"id": 5,
"url": "http://www.baidu.com1",
"switch": 0,
"order": 5,
"pid": 2,
"title": "這是測試的數(shù)數(shù)據(jù)2"
},
{
"id": 6,
"url": "http://www.taobao.com1",
"switch": 1,
"order": 6,
"pid": 0,
"title": "淘寶購物2"
}];
$.each(data, function (i, n) {
var row = $("#template").clone();
row.find("#id").text(n.id);
row.find("#url").text(n.url);
row.find("#title").text(n.title);
row.appendTo("#datas");//添加到模板的容器中
});
</script>
效果

更多關(guān)于jQuery相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《jQuery表格(table)操作技巧匯總》、《jQuery操作json數(shù)據(jù)技巧匯總》、《jQuery form操作技巧匯總》、《jQuery常用插件及用法總結(jié)》、《jQuery擴展技巧總結(jié)》及《jquery選擇器用法總結(jié)》
希望本文所述對大家jQuery程序設(shè)計有所幫助。
- jQuery獲取table下某一行某一列的值實現(xiàn)代碼
- jQuery中table數(shù)據(jù)的值拷貝和拆分
- jQuery獲取Table某列的值(推薦)
- 用jQuery獲取table中行id和td值的實現(xiàn)代碼
- jquery遍歷table的tr獲取td的值實現(xiàn)方法
- jQuery實現(xiàn)獲取table表格第一列值的方法
- jQuery學習筆記(4)--Jquery中獲取table中某列值的具體思路
- 模仿JQuery sortable效果 代碼有錯但值得看看
- JQuery動態(tài)給table添加、刪除行 改進版
- JQuery Ajax動態(tài)生成Table表格
- 使用jquery給指定的table動態(tài)添加一行、刪除一行
- 基于JQuery的動態(tài)刪除Table表格的行和列的代碼
相關(guān)文章
JQuery Mobile 彈出式登錄框的實現(xiàn)方法
下面小編就為大家?guī)硪黄狫Query Mobile 彈出式登錄框的實現(xiàn)方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-05-05
Jquery ajaxStart()與ajaxStop()方法(實例講解)
本篇文章主要是對Jquery中的ajaxStart()與ajaxStop()方法進行了介紹,需要的朋友可以過來參考下,希望對大家有所幫助2013-12-12
jQuery利用cookie 實現(xiàn)本地收藏功能(不重復(fù)無需多次命名)
cookie 是存儲于訪問者計算機中的變量。這篇文章主要介紹了jQuery利用cookie 實現(xiàn)本地收藏功能不重復(fù)無需多次命名,需要的朋友可以參考下2019-11-11
jQuery插件FusionCharts繪制的2D條狀圖效果【附demo源碼】
這篇文章主要介紹了jQuery插件FusionCharts繪制的2D條狀圖效果,結(jié)合完整實例形式分析了jQuery使用FusionCharts插件繪制2D條狀圖的具體步驟與相關(guān)操作技巧,并附帶demo源碼供讀者下載參考,需要的朋友可以參考下2017-05-05

