javascript - 如何根据条件更改 jtable 中列的特定行颜色?

标签 javascript jquery jsp jtable

 paymentStatus: {
                title: 'Payment Status',
                width: '8%',
                options: {'Paid': 'Paid', 'Due': 'Due'},
                create: false,
                edit: false,
                list: true
            },

更具体地说,我希望 paymentStatus 的颜色在“到期”时为红色,在“已支付”时为绿色。

Here is the screenshot of my web application

最佳答案

我不太了解 jtable,但你可以像这样在 Jquery 中这样做

$(function(){
    $('#studentlist tr td').each(function(){
        var i = $(this).index();
        // since i'm interested in the 3rd column, I check for i === 2
        // if you were interested in the 9th column, it would be i === 8
        if (i === 2) {
            $(this).addClass( $(this).text().toLowerCase() );
        }
    });
});
table td {
    border: 1px solid silver;
}

.due {
    background-color: red;
}

.paid {
    background-color: green;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table caption="student list" id="studentlist">
    <thead>
        <tr>
            <th>Name</th>
            <th>Room</th>
            <th>Payment</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Sean</td>
            <td>101</td>
            <td>Due</td>
        </tr>
         <tr>
            <td>Kyle</td>
            <td>230</td>
            <td>Due</td>
        </tr>
         <tr>
            <td>Mohammed</td>
            <td>169</td>
            <td>Paid</td>
        </tr>       
    </tbody>
</table>

关于javascript - 如何根据条件更改 jtable 中列的特定行颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29049370/

相关文章:

javascript - React Hook 函数组件防止重新渲染

Firefox 中的 jquery .focus() : functionally it works, 但从视觉上看,它并没有

javascript - jquery 编辑链接 href 如果 body class = x

javascript - 在页面之间显示 'Page Loading' 消息

javascript - 在 while 循环之外显示帖子描述

javascript - 禁用复选框和文本

java - HTTP 状态 500 - 无法编译 JSP : import cannot be resolved to a type 的类

java - 使用 jquery 或 jsp 或 javascript 在 html 中显示 Windows 目录结构。

javascript - 如何使用javascript在浏览器中测试从用户到服务器的延迟?

javascript - 如何仅在第一次访问时弹出模态窗口