js给table赋值
来源:互联网 发布:2016淘宝详情页尺寸 编辑:程序博客网 时间:2024/06/04 19:31
要求:用js实现给一个table赋值如上:(定义X=70)
【HTML】
<table class="table table-bordered"> <thead> <tr> <th colspan="5" class="active">经济条件较好地区学费表</th> </tr> <tr> <th></th> <th>4-8人班</th> <th>2-3人班</th> <th>1人班</th> <th>10人以上</th> </tr> </thead> <tbody data-json="area1"></tbody> </table> <table class="table table-bordered"> <thead> <tr> <th colspan="5" class="active">经济条件较好地区学费表</th> </tr> <tr> <th></th> <th>4-8人班</th> <th>2-3人班</th> <th>1人班</th> <th>10人以上</th> </tr> </thead> <tbody data-json="area2"></tbody> </table> <table class="table table-bordered"> <thead> <tr> <th colspan="5" class="active">经济发达地区学费表</th> </tr> <tr> <th></th> <th>4-8人班</th> <th>2-3人班</th> <th>1人班</th> <th>10人以上</th> </tr> </thead> <tbody data-json="area3"></tbody> </table>
【JS】
<script> require(["jquery"], function($) { var x=70; var data = [ {name:"area1",content:{bei:[1,1.2,1.5,0.8],jia:[20,30,40,50]}}, {name:"area2",content:{bei:[1,1.2,1.5,0.8],jia:[20,30,50,60]}}, {name:"area3",content:{bei:[1,1.2,1.5,0.8],jia:[20,40,60,80]}} ]; $(data).each(function (i,item){ dom = ''; bei = item.content.bei; jia = item.content.jia; //加载第1行 dom += '<tr>'; dom += '<td>第1学年</td>'; for(i=0;i<bei.length;i++){ dom += '<td>'+ parseInt(x*bei[i]) +'</td>'; } dom += '</tr>'; //循环加载第2+行 for(n=0;n<jia.length;n++){ dom += '<tr>'; dom += '<td>第'+(n+2)+'学年</td>'; for(i=0;i<bei.length;i++){ dom += '<td>'+ (parseInt(x*bei[i])+jia[n]) +'</td>'; } dom += '</tr>'; } $('[data-json="'+item.name+'"]').html(dom); }) }); }); </script>
0 0
- js给table赋值
- jquery 动态给table赋值
- js如何给赋值
- js 给数组赋值
- js给css赋值
- js给元素赋值
- js给select赋值
- js给html标签 赋值
- JS 给c#控件赋值
- php变量赋值给js
- js给下拉框赋值
- js给value动态赋值
- JS给对象属性赋值
- php变量赋值给js
- JS给Table增加行
- jquery table A赋值给同一行input
- js给服务器控件赋值注意事项
- JS给Img赋值IE兼容问题
- 字典树的C++实现
- Java中finally关键字的使用
- 为什么说Tomcat是一个Web服务器而不是一个应用服务器
- Servlet 中文乱码问题及解决方案剖析
- Leetcode 96 Unique Binary Search Trees
- js给table赋值
- Map Vector Set (离散的使用)
- Android 设置竖屏
- finished with non-zero exit value 2问题的常用解决方案
- FFT的物理意义 配波形图
- SSH项目中的文件划分
- 线程与进程的区别
- 对自定义UITableViewCell的理解
- 3.2ImplementstrStr