js动态生成表格【含合并单元格的表格】 |
您所在的位置:网站首页 › js原生table动态跨列合并 › js动态生成表格【含合并单元格的表格】 |
最近遇到需求,动态生成表格,类似Excel,支持合并单元格的表格,代码分享给大家~ 一、网上找到的简单生成表格的例子: 以下是生成规则表格m行*n列类似,可以直接打开HTML查看结果。 动态生成表格 行:; 列: function addTable() { var row1=document.getElementById("h").value;//获取属性值 var col1=document.getElementById("l").value;//获取属性值 var div1=document.getElementById("div1"); var tab=""; //循环行 for(var i=1;i"row_index": 0, "col_index": 2, "rowspan": 1, "colspan": 1,"correlation_value":"dfd"}] }, { "rowindex": 1, "collist": [{"row_index": 1, "col_index": 0, "rowspan": 2, "colspan": 1,"correlation_value":"dfd"}, { "row_index": 1, "col_index": 1, "rowspan": 1, "colspan": 1,"correlation_value":"dfd" }, {"row_index": 1, "col_index": 2, "rowspan": 1, "colspan": 1,"correlation_value":"dfd"}] }, { "rowindex": 2, "collist": [{"row_index": 2, "col_index": 1, "rowspan": 1, "colspan": 1,"correlation_value":"dfd"}, { "row_index": 2, "col_index": 2, "rowspan": 1, "colspan": 1,"correlation_value":"dfd" }] }]; for (var i = 0; i < json.length; i++) { appendStr += ""; //循环列 for (var j = 0; j < json[i].colList.length; j++) { appendStr += "" + json[i].colList[j].correlationValue+ ""; } appendStr += ""; } appendStr += '' + ' ' + ' ' + ' ' + ' ' + ''; //div_content为页面div,存放table用 $("#div_content").append(appendStr);效果图如下: —-第一次发博,大家可以多多沟通交流,提出宝贵意见哈~~~~~ |
今日新闻 |
点击排行 |
|
推荐新闻 |
图片新闻 |
|
专题文章 |
CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭 |