html table表格动态显示

html

html 复制代码
<table class="tab-scroll"  cellpadding="0" cellspacing="0" bgcolor="">
      <thead>
        <tr align="center">
           <th style="width: 50%;">问题名称</th>
           <th style="width: 50%;">涉及用户(局)</th>
        </tr>
      </thead>
   <tbody id="rankdetail2">
 </tbody>
</table>

js动态渲染数据

javascript 复制代码
方法一:
data = [
      {
        name: '世界你好1',
        relateCustomer: '111'
      },
      {
        name: '世界你好2',
        relateCustomer: '222'
      },
      {
        name: '世界你好3',
        relateCustomer: '333'
      },
      {
        name: '世界你好4',
        relateCustomer: '444'
      },
      {
        name: '世界你好5',
        relateCustomer: '555'
      },
      {
        name: '世界你好6',
        relateCustomer: '666'
      }
    ];
    for (var i = 0; i < result.data.length; i++) {
      var row = $('#rankdetail2')[0].insertRow(-1);
      var cell1 = row.insertCell(0);
      var cell2 = row.insertCell(1);
      cell1.innerHTML = data[i].name;
      cell1.style.textAlign = "center";
      cell2.innerHTML = data[i].relateCustomer;
      cell2.style.textAlign = "center"; 
    }
javascript 复制代码
方法二:
data = [
      {
        name: '世界你好1',
        relateCustomer: '111'
      },
      {
        name: '世界你好2',
        relateCustomer: '222'
      },
      {
        name: '世界你好3',
        relateCustomer: '333'
      },
      {
        name: '世界你好4',
        relateCustomer: '444'
      },
      {
        name: '世界你好5',
        relateCustomer: '555'
      },
      {
        name: '世界你好6',
        relateCustomer: '666'
      }
    ];
    var row = document.createElement("tr");
    var cell1 = document.createElement("td");
    var cell2 = document.createElement("td");
    cell1.innerHTML = data[i].name;
    cell1.setAttribute("style", "text-align: center;");  // 设置单元格中文字居中显示
    cell2.innerHTML = data[i].relateCustomer;
    cell2.setAttribute("style", "text-align: center;");  // 设置单元格中文字居中显示

    row.appendChild(cell1);
    row.appendChild(cell2);
    $('#rankdetail2')[0].appendChild(row);
相关推荐
mCell14 小时前
GSAP ScrollTrigger 详解
前端·javascript·动效
gnip14 小时前
Node.js 子进程:child_process
前端·javascript
RainbowSea16 小时前
12. LangChain4j + 向量数据库操作详细说明
java·langchain·ai编程
RainbowSea16 小时前
11. LangChain4j + Tools(Function Calling)的使用详细说明
java·langchain·ai编程
excel17 小时前
为什么在 Three.js 中平面能产生“起伏效果”?
前端
excel18 小时前
Node.js 断言与测试框架示例对比
前端
天蓝色的鱼鱼19 小时前
前端开发者的组件设计之痛:为什么我的组件总是难以维护?
前端·react.js
codingandsleeping19 小时前
使用orval自动拉取swagger文档并生成ts接口
前端·javascript
考虑考虑20 小时前
Jpa使用union all
java·spring boot·后端
石金龙20 小时前
[译] Composition in CSS
前端·css