HTML通过使用JS动态显示table内容

HTML:

<table border="1" id="tb">
   <thead>
    <caption>历史知识点对比</caption>
    <tr>
      <th rowspan="2">知识点</th>
      <th rowspan="2">全校得分率</th>
      <th rowspan="2">上次考试教师授课班级得分率</th>
      <th rowspan="2">本次考试教师授课本机得分率</th>
      <th colspan="3">本次分班级</th>
      <th rowspan="2">神经网络预测得分率</th>
       </tr>
       <tr>
      <th>1班</th>
      <th>2班</th>
      <th>3班</th>
    </tr>
  </thead>

</table>

 

 

JS:

/*动态显示表格内容*/
    window.οnlοad=function(){
        $.ajax({
            type:"get",
            url:"/getTableData",
            data:{},
            async: false,
            success:function (data) {
                //var data = eval('('+data+')');
                for(var i=0;i < data.length;i++){
                    var x=document.getElementById('tb').insertRow();
                    for(var j=0;j < data[i].length;j++){
                        var cell=x.insertCell();
                        cell.innerHTML=data[i][j];
                    }
                }
           }
        });
    }

 

主要使用了DOM的insertRow以及insertCell方法,该JS比较简洁,推荐使用,效果如下:

转载于:https://www.cnblogs.com/liesun/p/9196555.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值