本文实例讲述了jQuery实现动态给table赋值的方法。分享给大家供大家参考,具体如下:
html
请忽视各种class,因为前端用的是layui
js代码
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": "这是测试的数数据这是测试的数数据"
},{
"id": 3,"url": "http://www.taobao.com","order": 3,"title": "淘宝购物"
},{
"id": 4,"url": "http://www.jqcool.net1","order": 4,"title": "Online Program knowledge share and study platform2"
},{
"id": 5,"url": "http://www.baidu.com1","order": 5,"title": "这是测试的数数据2"
},{
"id": 6,"url": "http://www.taobao.com1","order": 6,"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");//添加到模板的容器中
});
更多关于jQuery相关内容感兴趣的读者可查看本站专题:《》、《》、《》、《》、《》及《》
希望本文所述对大家jQuery程序设计有所帮助。