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);
相关推荐
C2X7 小时前
关于Git Graph展示图的理解
前端·git
昊茜Claire7 小时前
鸿蒙开发之:性能优化与调试技巧
前端
雲墨款哥7 小时前
从一行好奇的代码说起:Vue怎么没有React的<StrictMode/>
前端
小肥宅仙女7 小时前
告别繁琐!React 19 新特性对比:代码量减少 50%,异步状态从此自动管理
前端·react.js
ohyeah7 小时前
柯理化(Currying):让函数参数一个一个传递
前端·javascript
CryptoRzz7 小时前
StockTV API 对接全攻略(股票、期货、IPO)
java·javascript·git·web3·区块链·github
iReachers7 小时前
为什么HTML打包安卓APP安装时会覆盖或者报错?
android·java·html·html打包apk·网页打包
纟 冬7 小时前
Flutter & OpenHarmony 运动App运动模式选择组件开发
android·java·flutter
毕设源码-赖学姐7 小时前
【开题答辩全过程】以 基于Springboot的智慧养老系统的设计与实现为例,包含答辩的问题和答案
java·spring boot·后端