异步请求数据加载到表格后根据不同状态改变表格背景颜色【表格背景色】

  有时候我们需要对不同数据的背景色加以区分,简单例子是将用户希望一眼看出来的数据加重颜色。

  思路:根据不同的状态修改每行开始的tr的背景色.

 var tr_start = papers[i].usetimes > 0 ? "<tr style='background-color:#96CDCD'>"
                : "<tr>";

 

 

例子:

// 填充表格
function showTable(data) {
    var result = eval("(" + data + ")");
    $("#paperTableBody").html("");// 清空表
    var papers = result.pageBean.productList;
    for (var i = 0, length = papers.length; i < length; i++) {
        var index = (result.pageBean.currentPage - 1) * 8 + i + 1;
        var tr_start = papers[i].usetimes > 0 ? "<tr style='background-color:#96CDCD'>"
                : "<tr>";
        $("#paperTableBody")
                .append(
                        tr_start
                                + "<td>"
                                + index
                                + "</td><td>"
                                + papers[i].title
                                + "</td><td>"
                                + papers[i].level
                                + "</td><td>"
                                + papers[i].paperscore
                                + "</td><td>"
                                + papers[i].usetimes
                                + "</td><td>"
                                + papers[i].description
                                + "</td><td>"
                                + papers[i].employeename
                                + "</td><td>"
                                + papers[i].maketime
                                + "</td><td>"
                                + "<a href='"
                                + contextPath
                                + '/update_findPaperAllInfoById.action?paperId='
                                + papers[i].paperid
                                + "'>修改</a><a href='javascript:void(0)' onclick='deletePaper(\""
                                + papers[i].paperid
                                + "\")'>删除</a><a href='"
                                + contextPath
                                + "/findPaper_findPaperAllInfoById.action?paperId="
                                + papers[i].paperid + "'>试卷预览</a>"
                                + "</td></tr>");
    }

 

结果:

 

posted @ 2017-12-02 21:42  QiaoZhi  阅读(471)  评论(0编辑  收藏  举报