/**
 * 创建表格
 * @param label 标题 json格式,数据结构见附录1
 * @param data 数据 json格式,数据结构见附录1
 * @param parentElement html元素,表格插入至此元素中
 */
function createTable(label, data, parentElement) {
    //创建表格
    var table = $("<table> </table>");
    //也可以为元素对象设定id,class等属性.
    /*var table = $("<table>",{
                      "id"    : "tableId",
                      "class" : "table_class"
                   });*/
    //设定样式
    table.css({
        width: "98%",
        "border-collapse": "collapse",
        border: "0px solid #d0d0d0",
        margin: "3px",
        "font-size": "14px"
    });
    //标题行
    var tr = $("<tr></tr>");
    tr.css({
        border: "1px solid #d0d0d0",
        height: "30px",
        color: "#FFF",
        background: "#37b5ad"
    });
    $.each(label, function (index, value) {
        var th = $("<th>" + value + "</th>");
        th.appendTo(tr);
    });
    tr.appendTo(table);

    $.each(data, function (index, row) {
        //数据行
        var tr = $("<tr></tr>");
        //数据列
        $.each(row, function (key, value) {
            //console.info(key + ":" + value);
            var td = $("<td>" + value + "</td>");
            td.css({
                border: "1px solid #d0d0d0",
                height: "24px"
            });
            td.appendTo(tr);
        });
        tr.appendTo(table);
    });
    table.appendTo(parentElement);
}
createTable

相关文章:

  • 2022-02-01
  • 2022-12-23
  • 2022-02-12
  • 2021-07-20
  • 2022-12-23
  • 2022-01-11
  • 2021-12-03
  • 2022-12-23
猜你喜欢
  • 2021-05-20
  • 2022-03-05
  • 2021-06-13
  • 2021-08-09
  • 2021-12-22
  • 2022-12-23
相关资源
相似解决方案