<table class="table table-hover fixed-table-container scrollTable" style="width: 100%;">
<thead style="font-size:12px;">
<tr id="table_thead_tr"></tr>
</thead>
<tbody class="Tbody" id="table_tbody_tr">
</tbody>
</table>
- // 载入表头数据
- var thJsonUrl = 'content/data/SJSB/' + pageType + '/teble_th.txt';
- $.ajax({
- url: thJsonUrl,
- dataType: "json",
- async: true,// 异步 true 还是同步 false 默认是 true
- complete: function (jsondata, stat) {
- if (stat == "success") {
- //alert("success");
- var datasource = eval("(" + jsondata.responseText + ")");
- for (var i = 0;i <datasource.length; i++ ) {
- //alert(datasource[i].name);
- $("#table_thead_tr").append("<th>" + datasource[i].name + "</th>");
- }
- }
- else if (stat == "error") {
- alert("error");
- };
- }
- });
- // 载入表内数据
- var tdJsonUrl = 'content/data/SJSB/' + pageType + '/teble_td.txt';
- $.ajax({
- url: tdJsonUrl,
- dataType: "json",
- async: true,// 异步 true 还是同步 false 默认是 true
- complete: function (jsondata, stat) {
- if (stat == "success") {
- //alert("success");
- var datasource = eval("(" + jsondata.responseText + ")");
- console.log(datasource);
- var stringTr = "", stringTd ="";
- $("#table_tbody_tr").html("");
- for (var i = 0; i <datasource.length; i++) {
- stringTd = "";
- for(var obj in datasource[i] )
- {
- console.log(datasource[i][obj]);
- stringTd += "<td>" + datasource[i][obj]+"</td>";
- }
- stringTr = "<tr>" + stringTd + "</tr>";
- $("#table_tbody_tr").append(stringTr);
- }
- }
- else if (stat == "error") {
- alert("error");
- };
- }
- });
th 的 json
- [
- {
- "name": "操作"
- },
- {
- "name": "类型"
- },
- {
- "name": "名称"
- },
- {
- "name": "状态"
- },
- {
- "name": "PH 值"
- }
- ]
td 的 json
- [
- {
- "col1": "<a> 新增 </a>",
- "col2": "河流",
- "col3": "大羊沟",
- "col4": "待审批",
- "col5": 0.6
- },
- {
- "col1": "<a> 查看 </a>",
- "col2": "河流",
- "col3": "大羊沟",
- "col4": "通过",
- "col5": 0.3
- }
- ]
来源: http://www.qdfuns.com/article/19533/655560e6b1c655ab22ac898817af5faa.html